DEV Community

Cover image for Getting Started with Machine Learning for Sentimental Analysis (Part 1)
AJ_Coding
AJ_Coding

Posted on

Getting Started with Machine Learning for Sentimental Analysis (Part 1)

What is Sentimental Analysis?

This type of analysis also goes by the name opinion mining. It consists of using NLP (Natural Language Processing), text analysis and computational linguistics techniques to extract subjective info from textual data.

It entails locating and classifying the attitudes, feelings, and views represented in a piece of writing, such a review, tweet, or news item. Sentiment analysis seeks to establish the presence and strength of positive, negative, or neutral sentiment in a given text. It is utilized in many different industries, such as social media analysis, customer service, and market research.

Types of Sentimental Analysis

Sentimental Analysis focuses primarily on the polarity of a text, that is whether the text is positive, neutral or negative. However, this method of analysis can be broader in that it can detect specific emotions as well. For example, a client is angry, sad, happy, fear etc.

It can also detect intentions, e.g. interested/not interested and even urgency. That is whether based on the input gathered and analyzed, is the customer in urgent need of a product or not.

Depending on the outcome required, we can tailor our analysis accordingly. The main types of sentimental analysis are as follows:

1) Polarity-based
This type of analysis puts emphasis on figuring out whether a sentiment is positive, negative or neutral. It then places a score depending on the polarity expressed. For example, positive = 4, neutral = 2 and negative = 0.

2) Aspect-based
Here we delve a bit deeper to find out what are the sentiments towards a specific aspect, feature, brand etc. The outcome of the analysis will give more information on what products/services are people mentioning in a negative/neutral/positive way.

3) Multilingual
This type of sentimental analysis deals with text input from different languages. It is able to obtain the sentiment of a text regardless of what language it is written in. This is especially useful for multinational companies or organizations that would like to know the feelings towards their products or services from their clientele in different countries.

4) Emotion-based
Suppose we would like to go beyond the basic polarity of a sentiment and we would like to know what are the types of emotions expressed in a piece of text such as fear, anger, happiness etc. This form of sentimental analysis would be best applied here.

5) Intent-based
We can also be able to tell what the intentions behind a certain text are. Was the sentiment meant to persuade, critique, recommend or provide praise? These are some of the outcomes of this type of analysis would be provide.

6) Contextual
This takes into account the context in which a piece of text was written. Context can include the date/ time, place, intended audience and the background of the writer. For example, based on context we can be able to identify negative or positive sentiment written by senior citizens during peak hours of the day.

7) Irony and Sarcasm
This type of sentimental analysis identifies whether the sentiment expressed is opposite to its intended meaning.

Benefits of performing sentimental analysis:

There are numerous benefits obtained from sentimental analysis:

1) Understanding customer opinions:
Can be used to assess how consumers feel about an organization’s goods and services. The outcomes of the analysis can help in learning what consumers like or dislike. This can then improve product development.

2) Brand reputation management:
May assist a company keep an eye on the perception of their brand by spotting negative sentiments and addressing them promptly in order to preserve a positive brand image.

3) Crisis management:
This is a bit similar to brand reputation management in that it also helps to mitigate an organization’s negative sentiments, however the main difference is that the latter helps to proactively build and maintain a company’s image over time while crisis management is focused on reducing or combating the impact of negative situations in a crisis such as a product recall or data breach.

4) Competitive analysis:

Using sentimental analysis, companies can compare the sentiments obtained from their own customers and compare them to their companies. This can bring to light areas where the business may be lacking and help to improve their products and services in order to better compete in the market.

5) Market insights:
Enables a company to establish their clientele’s preferences and trends. This information can then help in establishing more effective marketing strategies or campaigns that better align with the customers’ needs.

How is Sentimental Analysis performed?

There are three main approaches to performing sentiment analysis. These are namely:
• Rule-Based Approach
• Machine Learning Approach
• Hybrid Approach

The rule-based approach involves developing a rule set that identifies sentiment based on a specific phrases, keywords or text patterns. For example, a negative sentiment when the input text contains words such as ‘annoyed’, ‘poor’ etc.

A machine learning approach deals with establishing a sentiment from text by training a machine learning algorithm. The trained model then learns to recognize certain patterns and categorize them into positive, neutral or negative sentiments. The benefit of an efficiently trained machine learning algorithm is that it can be used to sort new input text in future with less hassle.

The third approach to performing sentiment analysis involves combining both machine learning and the rule based approach. In some instances, the machine learning model may not perform as well and in order to achieve prime accuracy, the rule-based approach may be used as well.

Our primary focus moving forward will be documenting how machine learning (ML) can be used to perform sentiment analysis on tweets, Facebook posts, news, movie reviews and any other platforms that document feedback from users and customers.

The main steps involved in any sentimental analysis project using ML are:
• Importing the data
• Cleaning and preprocessing the data
• Split the data into training/test sets
• Creating a model
• Training the model
• Make predictions
• Evaluate and improve

Some of the popular machine learning methods that we are going to implement to our analysis are:

1) Naive Bayes:
This algorithm deals primarily with the probability of a text belonging to a certain sentiment based on the frequency of words in the input text.

2) Deep Learning:
Using neural networks with multiple layers we can recognize patterns in a text.

3) Support Vector Machines (SVM):
Unlike Naïve Bayes, this method in non-probabilistic in that it used for text classification by finding the optimal hyper plane that can separate the positive and negative sentiments accordingly.

4) Decision Trees:
A tree-like model of decisions is built using this type of machine learning.

5) Random Forest:
Multiple decision trees are combined thereby improving the accuracy of the model that will be used for the analysis.

Our next article(s) will delve deeper into building a ML model from scratch after preprocessing the input text into clean arithmetic data that our model will be able to decipher and perform accurate sentiment analysis.

Top comments (0)