Explain Naïve Bayes along with a case study in R

1.0K    Asked by JoaquinaMesser in Data Science , Asked on Dec 18, 2019
Answered by Nitin Solanki

First we import the training and testing data

# Importing the dataset

training_set = read.csv(file.choose())#salary_train

test_set = read.csv(file.choose())# salary_test

Now we encode the target feature as factor and fit the model

# Encoding the target feature as factor

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

install.packages('e1071')

library(e1071)

classifier = naiveBayes(x = training_set[-14],y =training_set$Salary)

Now we predict and evaluate the model

# Predicting the Test set results

y_pred = predict(classifier, newdata = test_set[-14])

y_pred

# Making the Confusion Matrix

cm = table(test_set[, 14], y_pred)

cm



Your Answer

Interviews

Parent Categories