MCPcopy Create free account
hub / github.com/clips/pattern / test_sentiment_twitter

Method test_sentiment_twitter

test/test_en.py:889–911  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

887 print "pattern.en.sentiment()"
888
889 def test_sentiment_twitter(self):
890 sanders = os.path.join(PATH, "corpora", "polarity-en-sanders.csv")
891 if os.path.exists(sanders):
892 # Assert the accuracy of the sentiment analysis on tweets.
893 # Given are the scores for Sanders Twitter Sentiment Corpus:
894 # http://www.sananalytics.com/lab/twitter-sentiment/
895 # Positive + neutral is taken as polarity >= 0.0,
896 # Negative is taken as polarity < 0.0.
897 # Since there are a lot of neutral cases,
898 # and the algorithm predicts 0.0 by default (i.e., majority class) the results are good.
899 # Distinguishing negative from neutral from positive is a much harder task
900 from pattern.db import Datasheet
901 from pattern.metrics import test
902 reviews = []
903 for i, id, date, tweet, polarity, topic in Datasheet.load(sanders):
904 if polarity != "irrelevant":
905 reviews.append((tweet, polarity in ("positive", "neutral")))
906 A, P, R, F = test(lambda review: en.positive(review, threshold=0.0), reviews)
907 #print A, P, R, F
908 self.assertTrue(A > 0.824)
909 self.assertTrue(P > 0.879)
910 self.assertTrue(R > 0.911)
911 self.assertTrue(F > 0.895)
912
913 def test_sentiment_assessment(self):
914 # Assert that en.sentiment() has a fine-grained "assessments" property.

Callers

nothing calls this directly

Calls 4

testFunction · 0.90
existsMethod · 0.80
loadMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected