0% found this document useful (0 votes)
11 views

BI 8

Uploaded by

Aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

BI 8

Uploaded by

Aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Course Name: Business Intelligence Course Code: CSP-421

Experiment:3.1

Aim: To Implement Classification algorithm in R Programming.


IDE USED: R Studio
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.
Pseudo code/Algorithms/Flowchart/Steps:

1. Dataset Preparation

2. Exploratory Data Analysis

3. Programming Environment Setup

4. Implementing Classification algorithm in R

5. Selection of classification algorithm Naive Bayes

6. Model Evaluation and Interpretation

7. Analysis and Conclusion

Implementation (Code and Output):


getwd()
# Naive Bayes
# Importing the dataset
dataset = read.csv('Social_Network_Ads.csv')
print(dataset)
dataset = dataset[3:5]
print(dataset)

# Encoding the target feature as factor


dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1))
# Splitting the dataset into the Training set and Test set library(caTools)
split = sample.split(dataset$Purchased, SplitRatio = 0.75)
Name: Aditya Chauhan UID: 20BCS5742
Course Name: Business Intelligence Course Code: CSP-421

training_set = subset(dataset, split == TRUE)


test_set = subset(dataset, split == FALSE)

# Feature Scaling
training_set[-3] = scale(training_set[-3])
test_set[-3] = scale(test_set[-3])

# Fitting Naive Baiyes Classifier to the Training set library(e1071)


classifier = naiveBayes(x = training_set[-3], y = training_set$Purchased) print(classifier)

# Predicting train set results


y_pred_train = predict(classifier, newdata = training_set[-3])

# Making the Confusion Matrix for training


set cm_train = table(training_set[, 3], y_pred_train)
print(cm_train)

#Accuracy on training data


accuracy_train <- sum(diag(cm_train))/sum(cm_train)
cat("\nAccuracy on training set: ", accuracy_train)

# Predicting the Test set results


y_pred_test = predict(classifier, newdata = test_set[-3])

# Making the Confusion Matrix for testing


set cm_test = table(test_set[, 3], y_pred_test)

# Accuracy on test data


accuracy_test <- sum(diag(cm_test))/sum(cm_test)
cat("\nAccuracy on test set: ", accuracy_test)

Output:
Print Dataset
Name: Aditya Chauhan UID: 20BCS5742
Course Name: Business Intelligence Course Code: CSP-421

Print Confusion Matrix and Accuracy Score

Name: Aditya Chauhan UID: 20BCS5742

You might also like