Now, let's use the naive Bayes algorithm to solve the classifiers challenge:
- First, we import the GaussianNB() function and use it to train the model:
from sklearn.naive_bayes import GaussianNB
classifier = GaussianNB()
classifier.fit(X_train, y_train)
- Now, let's use the trained model to predict the results. We will use it to predict the labels for our test partition, which is X_test:
Predicting the Test set results
y_pred = classifier.predict(X_test)
cm = metrics.confusion_matrix(y_test, y_pred)
cm
- Now, let's print the confusion matrix:
- Now, let's print the performance matrices to quantify the quality of our trained model:
accuracy= metrics.accuracy_score(y_test,y_pred)
recall = metrics.recall_score(y_test,y_pred)
precision = metrics.precision_score(y_test,y_pred)
print(accuracy,recall,precision)
Which gives the output as: