0% found this document useful (0 votes)
24 views5 pages

Classification in R

This document describes an experiment in R programming to implement a classification algorithm for business intelligence. The steps include importing and preprocessing data, splitting it into training and test sets, training a classification model like decision trees or random forests on the training set, evaluating the model's performance on the test set using metrics like accuracy, and making predictions on new data with the trained model. The aim is to learn skills in applying classification algorithms and evaluating model performance in R for business intelligence tasks.

Uploaded by

Aman Kansal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
24 views5 pages

Classification in R

This document describes an experiment in R programming to implement a classification algorithm for business intelligence. The steps include importing and preprocessing data, splitting it into training and test sets, training a classification model like decision trees or random forests on the training set, evaluating the model's performance on the test set using metrics like accuracy, and making predictions on new data with the trained model. The aim is to learn skills in applying classification algorithms and evaluating model performance in R for business intelligence tasks.

Uploaded by

Aman Kansal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 5

Course Name: Business Intelligence Lab Course Code: 20CSP-421

Experiment:3.1

Aim: Implementation of Classification algorithm in R Programming.

Software Required: R Programing, VS Code

Description: The experiment involves using R programming to implement a classification algorithm for
business intelligence purposes. Participants will learn how to preprocess data, train a classification
model, evaluate its performance, and use it for predicting future outcomes.

Steps:

1.Import and Preprocess Data:

a. Launch R programming environment.


b. Load the required libraries and import the dataset for classification.
c. Perform data preprocessing tasks such as handling missing values, data transformation, and
feature scaling.
2.Split the Dataset:

a. Split the dataset into a training set and a testing/validation set.


b. Allocate a significant portion of the data for training the classification model.
3.Train the Classification Model:

a. Select an appropriate classification algorithm, such as Decision Trees, Naive Bayes, or Random
Forests.
b. Use the training set to train the classification model.
c. Configure and fine-tune the algorithm's parameters to optimize performance.
4.Evaluate Model Performance:

a. Apply the trained model to the testing/validation set.

Name: Aman Kansal UID: 20BCS9704


Course Name: Business Intelligence Lab Course Code: 20CSP-421

b. Calculate evaluation metrics such as accuracy, precision, recall, and F1-score to assess the model's
performance.
c. Use visualizations like confusion matrices and ROC curves to analyze the model's predictive power.
5.Make Predictions:

a. Use the trained classification model to make predictions on new, unseen data.
b. Apply the preprocessing steps performed earlier on the new data.
c. Generate predictions and interpret the results.

Outcome:
Step 1: Data Preparation
> # Load the Iris dataset
> data(iris)

Check the structure and summary of the dataset


> str(iris)

Name: Aman Kansal UID: 20BCS9704


Course Name: Business Intelligence Lab Course Code: 20CSP-421

> summary(iris)

Step 2: Data Splitting


Split the dataset into a training set (70%) and a testing set (30%)

> set.seed(123) # For reproducibility


> sample_indices <- sample(1:nrow(iris), 0.7 * nrow(iris))
> training_data <- iris[sample_indices, ]
> testing_data <- iris[-sample_indices, ]

Name: Aman Kansal UID: 20BCS9704


Course Name: Business Intelligence Lab Course Code: 20CSP-421

Step 3: Model Building


Train a logistic regression model
Train a multiclass logistic regression model

> model <- multinom(Species ~ ., data = training_data)

Step 4: Model Evaluation


Make predictions for the testing data

predicted_classes <- predict(model, newdata = testing_data, type = "class")

Create a confusion matrix to evaluate the model

> confusion_matrix <- table(observed = testing_data$Species, predicted =


predicted_ classes)
> print(confusion_matrix)

Calculate accuracy

Name: Aman Kansal UID: 20BCS9704


Course Name: Business Intelligence Lab Course Code: 20CSP-421

> accuracy <- sum(diag(confusion_matrix)) / sum(confusion_matrix)


> cat("Accuracy:", accuracy, "\n")

Accuracy: 0.9777778

Learning Outcomes

1.Gain proficiency in using R programming for implementing classification algorithms.

2.Understand the importance of data preprocessing in preparing data for classification tasks.

3.Learn different classification algorithms and their application in business intelligence.

4.Develop skills in training and fine-tuning classification models using R.

5.Acquire knowledge of evaluating classification model performance using various metrics and
visualizations.

6.Learn how to use trained classification models to make predictions on new data.

Name: Aman Kansal UID: 20BCS9704

You might also like