-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataClassify.py
More file actions
46 lines (38 loc) · 1.49 KB
/
dataClassify.py
File metadata and controls
46 lines (38 loc) · 1.49 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Mogamad Raa-iq Williams
Data Mining
'''
from numpy import zeros
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.metrics import classification_report
from dataImport import *
#Classification
print("-----------")
print("Classification")
print("-----------")
#Converting target array into integers for convenience
t = zeros(len(target))
t[target == 1] = 1
t[target == 2] = 2
#Instantiation and training of classifier
classifier = GaussianNB()
classifier.fit(data,t) #training on dataset
#Taking 40% of dataset as test values, retraining classifier and printing accuracy
train, test, t_train, t_test = train_test_split(data, t, test_size = 0.4, random_state = 0)
classifier.fit(train, t_train)
print("Accuracy of prediction using 40% of dataset as test values: ")
print(classifier.score(test,t_test))
#Below are a few ways of testing classifier that was established
'''
#Testing predict with sample
print("Classification using predict method: ")
print(classifier.predict(data[[0]]))
#Estimating performance of classifier once more by means of a confusion matrix
print("Confusion matrix to estimate performance of classifier: ")
print(confusion_matrix(classifier.predict(test),t_test))
'''
#Finally printing the summary of classifiers prediction accuracy and performance
print("Complete report of classifier performance: ")
print(classification_report(classifier.predict(test), t_test, target_names=['1','2']))