-
Notifications
You must be signed in to change notification settings - Fork 0
/
naive_bayes.py
28 lines (20 loc) · 923 Bytes
/
naive_bayes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from data import *
from sklearn.metrics import confusion_matrix
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import classification_report
from sklearn import metrics
import numpy as np
class NaiveBayes:
naive = Data()
# Generating the model
classifier = GaussianNB()
# Training the model on the Training set
classifier.fit(naive.x_train, naive.y_train.values.ravel()) # ravel --> Returns 1D array
# Predicting the test set results
y_predict = classifier.predict(naive.x_test)
# Making the Confusion Matrix
confusion_matrix = confusion_matrix(naive.y_test, y_predict)
# Checking the accuracy using classification_report
c_report = classification_report(naive.y_test, y_predict)
# The average of the squares of the errors
mean_square_error = metrics.mean_squared_error(np.asarray(naive.y_test),y_predict).round(2)