banner

Conducting Social Media Sentiment Analysis: A Working Example

Conducting Social Media Sentiment Analysis with a Working Example

Sentiment Analysis: Before we launch into why conducting social media sentiment analysis of your brand on social media is important, and how to go about doing sentiment analysis with Python, here’s a quick lowdown on sentiment analysis itself with a working example.

Table Of Contents

  1. Why is Sentiment Analysis Important for Businesses?
  2. What is Social Media Sentiment Analysis?
  3. Increasing Use of AI in Sentiment Analysis
  4. Benefits of Sentiment Analysis For Businesses
  5. Sentiment Analysis Crucial for Online Reputation Management
  6. Reasons Why Every Business Needs to Do It Right Now
  7. Sentiment Analysis Use Cases
  8. Sentiment Analysis Algorithm Types
  9. Here’s How To Conduct Social Media Sentiment Analysis Python (With Twitter As An Example)
  10. Two Techniques Of Sentiment Analysis
  11. VADER Sentiment Analysis Model
  12. Using VADER Sentiment Analysis

Why Sentiment Analysis?

Why is sentiment analysis important for businesses? Till a few years ago, analyzing a customer’s sentiments was not something that was taken seriously. Today, thanks to advancements in technology and also in the thinking of businesses, sentiment analysis is emerging as a viable tool. What makes it interesting and rather different from the other forms of data analytics is that this one deals with emotions, and as we all know, emotions are never black or white.


Express Analytics puts the voice of the customer at the heart of the business. Want to learn more about sentiment analysis using Python? Fill up this short form and our experts will touch base with you.


Sentiment analysis tells a brand or an enterprise what the world or the consumer feels about it. The sentiments could be positive, negative, or even neutral. Sentiment analysis is an algorithm-driven process, with the algorithms having access to a dictionary of words, each of them holding a positive, negative or neutral sentiment. Example: happy, sad, annoying, rewarding, lovely, wonderful, creative, etc.

To conduct such an analysis, a business must have the required tools in place and a clear idea of how to use them.

What Is Social Media Sentiment Analysis?

What is social media sentiment analysis and how to hold it? As the name signifies, sentiment analysis of social media means just that – to understand using data what people feel or think about your product, service, or even brand. Today, this has gone beyond the vanity metrics like likes, mentions, etc. Social media sentiment analysis means collecting and analyzing information in the posts people share about your company on social media.

Why is this form of analysis important? You get to know exactly what people think of your brand on social media. What are they saying? Are the majority happy or unhappy with your product? Why? Social media sentiment analysis helps you answer these types of questions.

Increasing Use Of AI in Sentiment Analysis

Because of advancements in Natural Language Processing (NLP), data analysts can segment client feedback as: positive, negative, or neutral with natural language.

NLP was largely being used in text analytics. With NLP, this form of analytics groups words into a defined form before extracting meaning from the text content. NLP is used to derive changeable inputs from the raw text for either visualization or as feedback to predictive models or other statistical methods.

But with the advent of new tech, there are analytics vendors who now offer NLP as part of their business intelligence (BI) tools. From the text, for example, NLP is now used to make sense of “voice” in interfaces such as digital voice assistants, or smart speakers like Amazon’s Alexa, as the latter becomes more and more interactive.

Sentiment Analytics

In sentiment analytics, to get a relevant result, everything needs to be put in a context or perspective. When a human uses a string of commands to search on a smart speaker, for the AI running the smart speaker, it is not sufficient to under “understand” the words. It also needs to bring in a context to the spoken words used, and try and understand the “searcher’s”, eventual aim behind the search.

What keeps happening in enterprises is the constant inflow of vast amounts of unstructured data generated from various channels – from talking to customers or leads to social media reactions, and so on. Now, to make sense of all this unstructured data you require NLP for it gives computers machines the wherewithal to read and obtain meaning from human languages.

Benefits Of Sentiment Analysis For Businesses

Companies can use sentiment analysis to identify their customers’ moods. By knowing the mood of your consumers, you can create products or provide services that will appeal to them.

For example, if your customers are unhappy about the economy, you can use this knowledge to create loyalty campaigns and new products.

Companies use sentiment analysis to improve customer service, develop better products, and gauge the overall satisfaction of their customers.

For example, if you analyze the ratings and reviews of your product and service and find that they’re overwhelmingly positive, it could indicate that there’s a good chance that people would be happy with it.

However, if your customers are overwhelmingly negative, it may indicate that there are some issues with the product or service.

The sentiment analysis tool scores whether an article or comment has positive, negative, or neutral sentiments towards a given topic.

Sentiment Analysis Crucial for Online Reputation Management

Sentiment is crucial for online reputation management. If you have a reputation online, and want it to be positive always, it is vital that you gather sentiments from your web page visits or social media channels to analyze the overall feelings your community has about your business.

Do people love what you’re doing? Are they indifferent or disappointed? It doesn’t matter how perfect your product or service is if no one knows about it!
If your company’s reputation is being damaged by bad comments on Facebook, Twitter, or other social media outlets, you need to rectify that at the earliest.

What’s more sentiment analysis is also a powerful marketing tool for it helps figure out customer emotions in a particular marketing campaign.

Reasons Why Every Business Needs to Do It Right Now

With social media becoming a vital aspect of marketing for businesses of all sizes, finding the best ways to analyze the online buzz surrounding a brand has become a new skill set. Sentiment analysis is the process of determining the sentiment expressed in a text.

It may be used to determine what emotions a group of words convey, such as how positive or negative a person is. In text mining, an automatic sentiment analysis can help determine if a message is positive or negative.

The sentiment analysis is the process of determining whether a piece of writing is positive, negative or neutral.

For example, if your post appears to be getting a lot of likes and shares, you can assume that your content is generally appealing to consumers. If you find that your post is getting a lot of dislikes and shares, then the chances are that you should do something to fix this.

Here are some other use-cases in business:

To upsell

You might be well aware of the benefits you offer customers, but what about those customers who have not yet discovered them?

This can be done with positive-sentiment based offerings, wherein the company offers more of the same product or service that is being used by existing customers.

This technique is effective for companies who have excellent reviews on their products or services, but are unsure of their brand perception among new customers.

To improve customer service

Just as a good relationship between a customer and a company grows over time, so does its influence in business growth.

A well-developed customer care system can help in strengthening such a relationship. The benefits of such a customer care system include:

Improved customer satisfaction: Identifying common customer grievances and enhancing the business’ capability to serve those needs.

The process begins with identifying the needs of individual customers, then identifying the business’ operational shortcomings.

With the information acquired from the analysis, businesses can improve their operations by revamping existing systems and processes, adding extra personnel or building an entirely new infrastructure to better serve customers.

For new marketing strategies

In today’s competitive market, businesses have to have a thorough understanding of their target audience. Market research results from the customer care database can help in uncovering exactly how customers interact with a business. Companies use results could lead to a complete market-tailored solution. A study about customer needs and behaviors, the way customers use a product or service, their preferences and demographics can help a business formulate effective marketing plans for optimum sales.sentiment analysis to find and encourage social networks and engage with their customers. For example, if a company has a Facebook page, it can analyze the likes and shares of its posts and determine how often people engage with them.

To tackle a crisis

Companies need to be able to react quickly to changes in their customer base. Analysis of what is happening with a particular customer can help to create better responses and prevent customer loss or damage caused by delayed action. On the other hand, investing resources in branding when no real change or apparent problems take place will only mean that they are throwing away money without getting anything back.

Sentiment Analysis Use Cases

Product review sentiment classification: When applied to review sentiment classification, the features or labels can be classified as polarities or not. If the analysis needs the classification as negative and positive, this is called a binary classifier.

If the analysis needs the classification as dark and light, this is called a sentiment polarity classifier.

Track customer sentiment versus time: Application of linear model in review sentiment analysis is the best method to extract trends between customer’s sentiment and time.

By finding the correlation coefficient between review sentiment and time, we can generate customer’s sentiment trend by finding the point where the correlation coefficient is the highest.

This process will show us how customers’ sentiments change over time.

Customer Sentiment Analysis models are used in almost every industry including travel, banking, e-commerce, food delivery and many more.

Sentiment Analysis Algorithm Types

Sentiment analysis can be achieved using different approaches, each with their own benefits and drawbacks. Here are the most popular types.

Supervised learning: Supervised learning is the most common approach for sentiment analysis. It relies on the existence of feature vectors that are applied to the training data before the classifier is trained.

These features consist of numerical descriptions for each message sent by customers, used as input into a series of statistical calculations which then determine how a given sentence should be classified as positive or negative.

This process is then repeated until all the data has been processed.

Unsupervised learning: Unlike supervised learning, in unsupervised learning no pre-defined feature vectors are used.

Instead, models learn from data itself and calculate features automatically by means of regression techniques or cluster analysis. This results in better classification accuracy because it does not rely on human-provided labels to make decisions.
In other words, it avoids the dependence on knowledge of the label set.

How to Conduct Social Media Sentiment Analysis Python (with Twitter as Example)

How to do twitter sentiment analysis in python? Here’s what is sentiment analysis example? The process, sentiment analysis python, by and large, can be duplicated across almost all social media networks (twitter). Data scientist Shubham Shankar shows you the way. You need to start by:

Understanding Your Market

Any python sentiment analysis starts from this point: understand your audience. Which means you need to understand how your audience feels about not only your brand but also about your various marketing campaigns.

Choose The Right Keywords, Hashtags, And Labels

Your business needs to choose specific keywords that sentiment analysis software detects like:

  • It’s great or it’s wonderful
  • It’s cheap or it’s expensive
  • It’s easy to use or
  • I didn’t like it

Then, you need to assign a sentiment score to each of these words. Obviously, it means positive feedback gets a higher sentiment score while negative feedback a lower one.

Two Techniques Of Sentiment Analysis

Before going ahead with this post on sentiment analysis with Python, you must understand that there are two techniques of this form of sentiment analysis.
Rule-based

Very simply put, this method uses a dictionary of words labeled by sentiment to determine the feeling put forth in a sentence. Like we said above, after a sentiment score is assigned, it needs to be combined with additional rules.

Machine learning-based

This takes out most of the human interactivity. In this technique, an ML algorithm is trained to recognize the thought based on the words and their order using a labeled training set. The technique is dependent on the type of algorithm and the quality of the training data. The “label” will be a measure of how positive or negative the sentiment is.

Sentiment analysis of Twitter with Python 

How to do sentiment analysis on twitter data using python step by step (sentiment analysis python)? For fetching the real-time data from Twitter, we will first need to get our key and access token using the official Twitter API Tweepy from the Twitter developer tool website. Once we have the keys, then we can proceed towards tweet extraction and creating the sentiment model.

Importing Necessary Libraries

We have to import all the required libraries.

sentiment analysis python

Getting Credentials

Now to extract the tweets from Twitter, we need to fill the consumer_key, consumer_secret, access_key, and access_secret and initialize the API as shown.

sentiment analysis using python

Before we start extracting the tweets, we must define the username of accounts for which we want to analyze the tweets. We can also define query words related to which we want our tweet data. Here, we will analyze tweets of 5 global organizations from their official Twitter accounts.

Extracting Tweets

Now, after defining organizations, we are ready to extract the tweets. Using the below-written code, we are extracting 100 tweets from each organization’s Twitter feed and store all the tweets in sentiment dictionary along with the user and date when the tweet gets posted.

extracting twitter data using python

Tweets data is in the dictionary, we convert it into a data frame for further processing. Now you can see the data pulled out from Twitter with tweets, User along post-date.

Twitter Sentiment Analysis using Python

extracting twitter data sentiment analysis

Cleaning the Twitter data

We are discussing conducting sentiment analysis with Python in this post with twitter example. Well, we fetched real-time tweets from Twitter, but now we have to extract meaningful insights from the tweet’s data. For that, we have to clean data because it contains lots of URLs, numbers, and user_ids, which get challenging to analyze tweets.
cleaning twitter data in python

VADER Sentiment Analysis Model

VADER (Valence Aware Dictionary for Sentiment Reasoning) is a model used for text sentiment analysis that is sensitive to both polarity (positive/negative) and intensity (strength) of emotion.Well, VADER sentiment analysis relies on a dictionary that maps lexical features to emotion intensities known as sentiment scores. Sentiment score of a text can be obtained by summing up the intensity of each word in the text.

Vader takes in a string and returns a dictionary of scores in each of four categories:

  • negative
  • neutral
  • positive
  • compound (computed by normalizing the scores above

Using VADER Sentiment Analysis

VADER is available in the NLTK package and can be applied directly to unlabeled text data as shown below.

vader sentiment analysis python

After initializing the analyzer, we can use polarity_scores() to find all the positive, negative, and neutral scores for each tweet.

Now using the compound score we will assign a sentiment label to each tweet.

sentiment analysis python vader

sentiment analysis

Now using the compound score we will assign a sentiment label to each tweet.

python sentiment analysis algorithm

sentiment analysis python applications

Conclusion

VADER classifies the sentiments very well. The ready-made model can be used across multiple domains, social-media texts, review texts, etc. It also does not require any training data and is very easy to use.


Build sentiment analysis models with Oyster

Whatever be your business, you can leverage Express Analytics’ customer data platform Oyster to analyze your customer feedback. To know how to take that first step in the process, press on the tab below.

Liked This Article?

Gain more insights, case studies, information on our product, customer data platform

Leave a comment

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap
  • Contact us

    Contact us