-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultinomialNB.txt
More file actions
31 lines (20 loc) · 799 Bytes
/
MultinomialNB.txt
File metadata and controls
31 lines (20 loc) · 799 Bytes
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
x=df.iloc[:,1]
y= df.iloc[:,0]
from sklearn.feature_extraction.text import CountVectorizer
cv = CountVectorizer(analyzer = 'word',lowercase = True)
x_poly = cv.fit_transform(x).toarray()
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x_poly,y,train_size =0.80,random_state=42)
from sklearn.naive_bayes import MultinomialNB
clf1 = MultinomialNB()
clf1=clf1.fit(x_train, y_train)
y_pred1 = clf1.predict(x_test)
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred1)
print(cm)
from sklearn.metrics import accuracy_score, classification_report
print(accuracy_score(y_test, y_pred1))
print(classification_report(y_pred1, y_test))
# print(y_pred.mean())
# from collections import Counter
# Counter(y_test)