Solution to Twitter Sentiment assignment in Introduction to Data Science(Coursera)
- Get Twitter Data: Copy API credentials into the given twitterstream.py and run the following for 10 minutes:
python twitterstream.py > output.txt
- Derive the sentiment of each tweet: Compute the sentiment of each tweet based on the sentiment scores of the terms in the tweet. Each word or phrase found in a tweet, but not in AFINN-111.txt should be given a sentiment score of 0. Example:
$ python tweet_sentiment.py AFINN-111.txt output_first_20.txt
0.0
0.0
0.0
0.0
0.0
0.0
-1.0
...
- Derive the sentiment of new terms: Computes the sentiment for the terms that do not appear in the file AFINN-111.txt Example:
$ python term_sentiment.py AFINN-111.txt output_first_20.txt
jaja -0.125
paramore 0.142857142857
just -0.0454545454545
...
- Compute Term Frequency: Print relative word frequency in a Twitter Stream file. Example:
>>> python frequency.py output_first_20.txt
jaja 0.00555555555556
paramore 0.00555555555556
just 0.00555555555556
...
- Which State is happiest?: Returns the code of the happiest state as a string. The average tweet happiness for each state is used as metric. Example:
$ python happiest_state.py AFINN-111.txt output.txt
KS
- Top ten hash tags: Computes the ten most frequently occurring hash tags from a tweet file. Example:
$ python top_ten.py output.txt
gameinsight 77.0
TFBJP 65.0
RT 53.0
5DebilidadesMias 51.0
...