Sentiment Analysis Using Python

Hey! In this article, we will see the sentiment analysis using Python

What is Sentiment Analysis?

The process of computationally identifying and categorizing opinions expressed in a piece of text, especially in order to determine whether the writer's attitude towards a particular topic is positive, negative, or neutral.

For this, we will use python’s Textblob Library.

Firstly, install textblob library using “pip install textblob”

Sentiment Analysis using Python

Note
Subjectivity and polarity are the two factors that Textblob will function with.

1) If a sentence has a high subjectivity score, which is near to 1, it suggests that the text contains more personal opinion than factual information. The subjectivity score ranges from 0 to 1, indicating the quantity of personal opinion.

2) The polarity score ranges from (-1) to (1), where (1) indicates the most positive terms, such as "great" and "best," and (-1) identifies the most negative words, such as "disgusting" and "terrible."

Now lets use it!

# Sentiment Analysis

# using or importing textblob
from textblob import TextBlob
text = input("Enter the text you want to analyze\n")


obj = TextBlob(text)  # textblob sentence to get polarity

sentiment, subjectivity = obj.sentiment  # get sentiments
print(obj.sentiment)  #print(sentiment, subjectivity)

if sentiment == 0:

    print('The text is neutral')

elif sentiment > 0:

    print('The text is positive')

else:

    print('The text is negative')

Examples

The Text is Positive

Sentiment Analysis using Python

The Text is Negative

Sentiment Analysis using Python

The Text is Neutral

Sentiment Analysis using Python

The Textblob is giving the sentiement analysis based on polarity and subjectivity score.


Similar Articles