ONLINE SUMMER TRAINING Online Courses Free Tutorials 
 Placement Preparation 
Artificial Intelligence(AI) & Machine Learning(ML) Training in Jaipur
0 like 0 dislike
196 views
in Python Programming by Goeduhub's Expert (3.1k points)
How do you do sentiment analysis on Twitter data using Natural Language Processing

Goeduhub's Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

Apply Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Computer Vision with OpenCV | Deep Learning CNN Projects

Apply Coupon

3.

Complete Machine Learning & Data Science with Python Apply Coupon

4.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

5.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon

6.

Complete Python Programming from scratch with Projects Apply Coupon

1 Answer

0 like 0 dislike
by Goeduhub's Expert (3.1k points)
edited by
 
Best answer

what is sentiment analysis ?

Sentiment analysis (opinion mining), it is the process of determining the emotional tone behind a series of words, used to gain an understanding of the the attitudes, opinions and emotions expressed within an online mention.

Why do we need sentiment analysis ?

Let's take an example of mobile phones

Suppose you have a plan to buy a phone but before buying a mobile, we read the reviews  and see the rating, which shows us how successful the product is. 

This what we are talking about is sentiment analysis.

Sentiment analysis is important from the customer's point of view because they can gain information about the product they are thinking of buying.

It is also useful for companies for making product better on customer demand by identifying and categorizing opinion expressed in piece of text, rating etc...

How sentiment analysis works ?

Sentiment Analysis is a procedure used to determine if a chunk (group) of text is positive, negative or neutral and emotions behind the text.

Polarity

Polarity is a float value within the range [-1.0 to 1.0] where 0 indicates neutral+1 indicates a very positive sentiment and -1 represents a very negative sentiment.

Subjectivity 

subjectivity is a float value within the range [0.0 to 1.0] where 0.0 is very objective and 1.0 is very subjective. Subjective sentence expresses some personal feelings, views, beliefs, opinions, allegations, desires, beliefs, suspicions, and speculations where as Objective sentences are factual.

TextBlob 

TextBlob is a Python library for processing textual data.It provides a simple API for diving into common natural language processing (NLP) tasks such as part-of-speech tagging, noun phrase extraction, sentiment analysis, classification, translation, and more.

For conceptual clarity of NLP (Natural Language Processing) -Click Here 

Tweepy: Tweepy is a Python library for accessing the Twitter API.

Installation of TextBlob and Tweepy 

-pip install textblob 

-pip install tweepy

Practical Implementation

#Import required libraries 

import tweepy 

from textblob import TextBlob

#Getting access to twitter data 

consumer_key='NiQsBDjlRWpQ3feDFlFPOIQ1S'

consumer_secret='eet7axREyPLMfzK2ejVaJjETzUiwGf3I9tGFFciJTNn4YJ6IHQ'

access_token='750782455683121154-4K1Ltq50DjXRs6A2fn3psytkspDl5o8'

access_token_secret='LRozr69SdslinsHa5vjluCrbKIEZRx7iaezt77ANDiH92'

auth = tweepy.OAuthHandler(consumer_key,consumer_secret)

auth.set_access_token(access_token,access_token_secret)

api=tweepy.API(auth)

#Searching public tweet on a topic

public_tweets=api.search('Coronavirus India')

#Preprocessing of data (twitter data)

for tweet in public_tweets:

    print(tweet.text)

    analysis=TextBlob(tweet.text)

    print(analysis.sentiment)

Output

coronavirusindia

Let's understand the code first 

After importing required libraries we accessed Twitter data for which we need some tokens.After that, we searched a topic to see the tweets (opinion) of people/nation  about the topic ,here (India Coronavirus).

In order to machine to understand and read our comments, we used natural language processing (TextBlob).

Output 

As you can see in the output there are comments saying about topic (that we searched -coronavirus India).

I have marked two comments with a red circle to understand how sentiment analysis works.As you can see in our first comment polarity and subjectivity both are 0 means the comment is Neutral and very Objective (Factual).

And in the second circle (Second comment) polarity is in positive means the comment says something positive (here India is much better ... ) and comment is little subjective means some emotions are reflected in comment.

How to get consumer key , consumer secret, access token and access token secret ?

  1. To get a consumer key sign in with your twitter account on https://developer.twitter.com/en. 
  2. Create a Twitter developer app.
  3. Follow the steps and answer the questions asked.
  4. After authentication app (you will receive a email for this).
  5. Generate your app's API keys and user's access tokens.
  6. Copy and use them.


Machine Learning Tutorial

Free Online Tutorials

NLP Tutorial  

Our Mentors(For AI-ML)


Sharda Godara Chaudhary

Mrs. Sharda Godara Chaudhary

An alumna of MNIT-Jaipur and ACCENTURE, Pune

NISHA (IIT BHU)

Ms. Nisha

An alumna of IIT-BHU

Related questions

0 like 0 dislike
1 answer 300 views
0 like 0 dislike
1 answer 539 views
0 like 0 dislike
2 answers 257 views

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...