Last active
November 5, 2020 17:53
-
-
Save Sanket758/ead7c5172d5eee0e6c2c6406f2871d77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!pip install afinn | |
from afinn import Afinn | |
afn = Afinn() | |
# Predicting sentiment on our reviews | |
sentiment_polarity = [afn.score(review) for review in test_reviews] | |
predicted_sentiments = ['positive' if score >= 1.0 else 'negative' for score in sentiment_polarity] | |
# Evaluation | |
from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, confusion_matrix | |
print('Accuracy:', accuracy_score(test_sentiments, predicted_sentiments)) | |
print('Precision:', precision_score(test_sentiments, predicted_sentiments, pos_label='negative')) | |
print('Recall:', recall_score(test_sentiments, predicted_sentiments, pos_label='negative')) | |
print('F1 Score:', f1_score(test_sentiments, predicted_sentiments, pos_label='negative')) | |
print('Confusion Matrix:\n', confusion_matrix(test_sentiments, predicted_sentiments)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment