Assignment No 6 - Polarity

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Honours* in Data Science #Fourth year of Engineering (Semester VII) #410502:

Machine Learning and Data Science Laboratory


Dr. Girija Gireesh Chiddarwar
Assignment No 6 -Write a program to recognize a document is positive or negative
based on polarity words using suitable classification method.

Sentiment analysis (SA), also known as opinion mining, is considered a natural


language approach that analyzes people’s attitudes about a specific product or
topic.
SA is the purpose of automatic analysis of an online document, such as a blog,
comment, review, and other new items like a comprehensive sentiment, and summarizes
it as positive, negative, or neutral 

Different Levels of Sentiment Analysis


There are three levels on which SA can be conducted
Document level: This approach considers the entire document (e.g. a comment or
review) as a basic information unit, and then classifies it as positive, negative,
or neutral. However, in some cases, the results given by this approach are
incompatible; for example, a document that has positively recognized a particular
item does not indicate that the author seems to have only positive opinions about
all features of that item. Similarly, a document that has negatively recognized an
item does not indicate that the author is completely negative about all features of
that item. Typically, authors convey both positive and negative sentiments about a
particular item and its features.
Sentence level: This approach attempts to establish the opinion expressed in each
sentence by breaking the entire document into sentences, with each sentence handled
as a separate information unit. It is first recognized whether a sentence is
subjective or objective, and then it is decided whether the sentence conveys a
positive or a negative opinion.
Aspect level: This approach performs a fine-grained analysis to identify relevant
aspects and entities of a particular item, and the sentiment/polarity is expressed
toward each aspect. Here is an aspect that refers to a feature of a particular
item, e.g. the battery life of a mobile phone.

Sentiment Analysis
Sentiment analysis is basically the process of determining the attitude or the
emotion of the writer, i.e., whether it is positive or negative or neutral.
The TextBlob package for Python is a convenient way to do a lot of Natural Language
Processing (NLP) tasks. 
TextBlob aims to provide access to common text-processing operations through a
familiar interface. You can treat TextBlob objects as if they were Python strings
that learned how to do Natural Language Processing.
The sentiment function of textblob returns two properties, polarity,
and subjectivity.
Polarity is float which lies in the range of [-1,1] where 1 means positive
statement and -1 means a negative statement.
Subjective sentences generally refer to personal opinion, emotion or judgment
whereas objective refers to factual information. Subjectivity is also a float which
lies in the range of [0,1].

Textblob
print (blob)
blob.sentiment
>> Analytics is a great platform to learn data science. Sentiment(polarity=0.8,
subjectivity=0.75)
We can see that polarity is 0.8, which means that the statement is positive
and 0.75 subjectivity refers that mostly it is a public opinion and not a factual
information.

Algorithm
Import required packages
Create the document to check sentiments
Open the file to read
Using classifier find the polarity
Check polarity to declare whether sentiment is positive or negative

You might also like