-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathp7.py
35 lines (29 loc) · 1.02 KB
/
p7.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
29
30
31
32
33
34
35
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.metrics import classification_report, accuracy_score
data = [
("I love this movie", "positive"),
("This film was amazing", "positive"),
("I actually enjoyed it", "positive"),
("I hated that movie", "negative"),
("This film was terrible", "negative"),
("I did not like it", "negative")
]
text, label = zip(*data)
vect = CountVectorizer()
X = vect.fit_transform(text)
clf = MultinomialNB().fit(X, label)
test = [
"I love this film",
"I hated the movie",
"It was an awesome movie",
"This movie was not good"
]
X_test = vect.transform(test)
y_pred = clf.predict(X_test)
print("Predicted labels:", y_pred)
# Actual labels for the test data
true_labels = ["positive", "negative", "positive", "negative"]
print("Classification Report:")
print(classification_report(true_labels, y_pred))
print("Accuracy Score:", accuracy_score(true_labels, y_pred))