-
Notifications
You must be signed in to change notification settings - Fork 10
/
9. challenge.py
25 lines (18 loc) · 887 Bytes
/
9. challenge.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
from reviews import counter, training_counts
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# Add your review:
review = "Its good"
review_counts = counter.transform([review])
classifier = MultinomialNB()
training_labels = [0] * 1000 + [1] * 1000
classifier.fit(training_counts, training_labels)
neg = (classifier.predict_proba(review_counts)[0][0] * 100).round()
pos = (classifier.predict_proba(review_counts)[0][1] * 100).round()
if pos > 50:
print("Naive Bayes classifies this as positive.")
elif neg > 50:
print("Naive Bayes classifies this as negative.")
else:
print("Naive Bayes cannot determine if this is negative or positive.")
print("\nAccording to our trained Naive Bayes classifier, the probability that your review was negative was {0}% and the probability it was positive was {1}%.".format(neg, pos))