Skip to content

Instantly share code, notes, and snippets.

@Sanket758
Last active November 5, 2020 17:53
Show Gist options
  • Save Sanket758/ead7c5172d5eee0e6c2c6406f2871d77 to your computer and use it in GitHub Desktop.
Save Sanket758/ead7c5172d5eee0e6c2c6406f2871d77 to your computer and use it in GitHub Desktop.
#!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