BI 8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy