You are on page 1of 4

DEPARTMENT OF

Experiment 2.2

Student Name: Pratyush kumar UID: 20BCS5572


Branch: CSE Section/Group: DM_901_B
Semester: 6TH Date_of_Performance:11/04/2023
Subject Name: Data Mining

1. Aim/Overview of the practical: Performing classification by Naïve byes classifier

2. Theory:
Naive Bayes classifier is a probabilistic machine learning algorithm that is commonly used for classification
problems. The algorithm is based on Bayes' theorem, which states that the probability of an event occurring
based on prior knowledge of conditions that might be related to the event.
In a Naive Bayes classifier, each feature is considered independently of other features, and the algorithm
makes a naive assumption that the features are all independent of each other. This simplifies the calculations
required to determine the probability of a particular classification for a given set of features.

3.Steps for experiment/practical/Code:

setwd("C:\\Users\\dell\\Desktop\\r work") dataset

= read.csv('Social_Network_Ads.csv') dataset =

dataset[3:5]

dataset$Purchased = factor(dataset$Purchased, levels = c(0, 1))

library(caTools) split = sample.split(dataset$Purchased,

SplitRatio = 0.75) training_set = subset(dataset, split ==

TRUE) test_set = subset(dataset, split == FALSE)

training_set[-3] = scale(training_set[-3]) test_set[-3]

= scale(test_set[-3])
DEPARTMENT OF

library(e1071) classifier = naiveBayes(x =

training_set[-3],

y = training_set$Purchased)

print(classifier)

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

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

print(cm_train) accuracy_train <-

sum(diag(cm_train))/sum(cm_train) cat("\nAccuracy on

training set: ", accuracy_train) y_pred_test =

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

table(test_set[, 3], y_pred_test) print(cm_test)

accuracy_test <- sum(diag(cm_test))/sum(cm_test)

cat("\nAccuracy on test set: ", accuracy_test)


DEPARTMENT OF

Output-
DEPARTMENT OF

You might also like