Twitter Sentiment Analysis

анализируем твиттер・Twitter の分析・Analyzing Twitter

Twitter Sentiment Analysis

Something cool you can do with the Twitter API is doing analysis on tweets. Using NLTK and some other libraries, you can run sentiment analysis on your queries.

By using the TextBlob library for NLP (Natural Language Processing), you can extract user’s tweet’s biases. Bias is measured in terms of Subjectivity and Polarity After gaining insights into individual tweet’s sentiment, you can query tweets from a given language and request up to around 10,000 queries. Using this data, I calculated median sentiments on a query which gets rid of the outliers in sentiment. Using matplotlib you can also plot out these tweets, providing a more visual representation of twitter sentiments.

Some sample output for the query “Bernie Sanders”:

10000 Results loaded!
Positive polarity:: 31.91%
Negative polarity:: 30.09%
Positive subjectivity:: 70.84%
Negative subjectivity:: 0.0%
Median polarity:: 0.0
Median subjectivity:: 0.25

Click here for the code