Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP809 Data Mining andMachine Learning

Week 8– Naive Bayes Classifier

Ø Two major objectives of this lab are to

o configure Pythons implementation of Naive Bayes classifier

o to evaluate these classifiers using a variety of different metrics.

Ø Configuring classifiers will be achieved using Python’s sklearn library. Evaluation will also be done via sklearn but use a dedicated set of methods designed specifically for computing metrics.

Same Dataset with Lab 7.

We had made some experiments about Decision Tree classifier in Lab 7.

Configure the Naive Bayes classifier with the Gaussian option for numeric data

gnb = GaussianNB() #suitable for numeric features

gnb.fit(pred_train, np.ravel(tar_train,order='C')) predictions

= gnb.predict(pred_test)

print("Accuracy score of our model with Gaussian Naive

Bayes:", accuracy_score(tar_test, predictions))

Configuring the Multinomial Naïve Bayes Classifier

By referring suitable information online identify the version of Naive Bayes suitable for classifying discrete data and fill in the line below.

mnb = MultinomialNB() #optimized for nominal features but can work for numeric ones as well

mnb.fit(pred_train, np.ravel(tar_train,order='C'))

predictions = mnb.predict(pred_test)

print("Accuracy score of our model with Multinomial Naive Bayes:", accuracy_score(tar_test, predictions))

•   Present the model results to a table in a word document, like the given examples.

The result table with the accuracy is usually not enough. It is recommended to calculate and provide metrics such as precision, recall, F Measure and confusion matrix in a report.