You won’t believe who is the least positive person on Twitter (according to AI and Data Science)

Original article was published on Artificial Intelligence on Medium


Artificial Intelligence (AI) and Data Science are getting a lot of attention these days. A lot of the talk is still very theoretical but we can see more and more examples of practical AI in the business context.

In this article, I would like to show an example of practical AI using Natural Language Processing (NLP) and sentiment analysis.

I’m using posts (tweets) from Twitter as an example but similar analysis can be used to automatically analyse comments on your social media posts, reviews of your company, your products and your services, support tickets, emails or free text from surveys to get an idea of the mood that is coming from people engaging with your business online. This could be as simple analysis as I’m presenting below or much more sophisticated algorithm taking into consideration many different factors. This can be a useful tool for your business when taking strategic, branding and marketing decisions.

I am going to use Data Science and NLP to find out which, of subjectively selected Twitter accounts, is the most positive based on analysing last 50 tweets of each account.

Algorithm

  • Take the last 50 tweets of the selected Twitter account.
  • Remove mentions, hashes, retweets and URLs.
  • Analyse each tweet in terms of subjectivity and polarity.
  • Remove all tweets with polarity 0.
  • Calculate the mean of subjectivity and polarity.
  • Once calculated for all accounts order accounts by polarity from the highest score to the lowest score.

Subjectivity is a number within the range [0.0, 1.0] where 0.0 is very objective and 1.0 is very subjective.

Polarity is a number within the range of [-1,1] where 1 means positive statement and -1 means a negative statement.

The analysis includes tweets and replies of a particular account.

Ranking

1. Susan Wojcicki — YouTube CEO

Polarity: 0.34, Subjectivity: 0.56, Positive tweets: 88%

The most positive Tweet. Polarity: 1.0

The most popular words from the tweets.

2. Tim Cook — Apple CEO

Polarity: 0.32, Subjectivity: 0.57, Positive tweets: 91%

The most positive Tweet. Polarity: 1.0

The most popular words from the tweets.

3. Jacinda Ardern — Prime Minister of NZ

Polarity: 0.29, Subjectivity: 0.61, Positive tweets: 90%

The most positive Tweet. Polarity: 1.0

The most popular words from the tweets.

4. Richard Branson — Founder of Virgin Group

Polarity: 0.26, Subjectivity: 0.52, Positive tweets: 88%

The most positive Tweet. Polarity: 0.80

The most popular words from the tweets.

5. Elon Musk — Founder of SpaceX

Polarity: 0.25, Subjectivity: 0.54, Positive tweets: 85%

The most positive Tweet. Polarity: 1.0

The most popular words from the tweets.

6. Boris Johnson — Prime Minister of the United Kingdom

Polarity: 0.22, Subjectivity: 0.64, Positive tweets: 82.5%

The most positive Tweet. Polarity: 0.80

The most popular words from the tweets.

7. Bill Gates — Co-founder of Microsoft

Polarity: 0.21, Subjectivity: 0.57, Positive tweets: 72%

The most positive Tweet. Polarity: 0.90

The most popular words from the tweets.

8. Oprah Winfrey — American talk show host

Polarity: 0.20, Subjectivity: 0.49, Positive tweets: 75%

The most positive Tweet. Polarity: 1.0

The most popular words from the tweets.

9. Barack Obama — 44th president of the United States of America

Polarity: 0.15, Subjectivity: 0.44, Positive tweets: 74%

The most positive Tweet. Polarity: 0.65

The most popular words from the tweets.

10. Donald Trump — 45th President of the United States of America

Polarity: -0.09, Subjectivity: 0.64, Positive tweets: 33%

The most positive Tweet. Polarity: 0.74

The most popular words from the tweets.

Technology

Python, Pandas, TextBlob, WordCloud, Twitter API

Summary

I hope I was able to show in this article how this seemingly basic tool can provide a lot of useful information to any business in an automatic and quick way.

This list of Twitter accounts is a little bit random and subjective but if you have any suggestions and would like me to add somebody to this list please add the name in the comments. Feel free to suggest your own Twitter account if you are not afraid of scrutiny 😉 The polarity score for my Twitter account @pjarz is 0.23 and subjectivity is 0.47 which would have placed me somewhere in the middle of this ranking.

I also hope that I managed to, apart from showing a little bit of Data Science and NLP, spread some positivity in this article (despite the headline). I’m even wondering when we’re going to see “You are a positive person” badge next to our name on social media accounts. Just an idea 🙂