SlideShare a Scribd company logo
Twitter Sentiment Analysis using
Python and NLTK
Presentation by:
ASHWIN PERTI,
Department of IT
Sentiment Analysis using PYTHON
The purpose of this Sentiment Analysis is:
● Able to automatically classify a tweet as a
positive
OR
● Negative tweet Sentiment wise
Sentiment Analysis using PYTHON
● The classifier needs to be trained:
● We need a list of manually classified tweets.
Positive Tweets
● I love this car
● This view is amazing
● I feel great this morning
● I am so excited about the concert
● He is my best friend
Negative Tweets
● I do not like this car
● This view is horrible
● I feel tired this morning
● I am not looking forward to the concert
● He is my enemy
Test Tweets
● TEST SET – to assess the exactitude of the
trained classifier
● I feel happy this morning. positive
● Larry is my friend. positive
● I do not like that man. negative
● My house not great. negative
● Your song annoying. negative
CLASSIFIER
● The list of word features need to be extracted
from the tweets.
● It is a list with every distinct words ordered by
frequency of appearance.
CLASSIFIER – Feature Extractor
● To decide which features are more relevant.
● The one we are going to use returns a
dictionary indicating that words are contained
in the input passed.
● INPUT - tweet
classifier=nltk.NaiveBayesClassifier.
train(training_set)
Naive Bayes Classifier
● It uses the prior probability of each label – which is
the frequency of each label in the training set and the
contribution from each feature.
● In our case, the frequency of each label is the same
for 'positive' and 'negative'.
● Word 'amazing' appears in 1 of 5 of the positive
tweets and none of the negative tweets.
● This means that the likelihood of the 'positive' label
will be multiplied by 0.2 when this word is seen as
part of the input.
CLASSIFY
● Now that we have our classifier initialized,
● Classify a tweet and
● See what the sentiment type output is:
● Our classifier is able to detect that this tweet
has a positive sentiment because
● Of the word 'friend'
● Which is associated to the positive tweet:
● 'He is my best friend'
print extract_features(tweet2.split())
● 'contains(looking)': False,
'contains(feel)': False,
● 'contains(the)': False,
● 'contains(excited)': False,
● 'contains(about)': False,
● 'contains(great)': False,
● 'contains(horrible)': False,
● 'contains(car)': False,
● 'contains(this)': False,
● 'contains(best)': False,
● 'contains(friend)': True,
● 'contains(concert)': False,
● 'contains(forward)': False,
● 'contains(view)': False,
● 'contains(tired)': False,
● 'contains(like)': False,
● 'contains(love)': False,
● 'contains(amazing)': False,
● 'contains(enemy)': False,
● 'contains(not)': True,
● 'contains(morning)': False}

More Related Content

PDF
Sentiment analysis-by-nltk
PPTX
Python NLTK
PPT
Jsp abes new
PPT
Get_vs_Post
ODP
Word sense dissambiguation
PDF
2024 Trend Updates: What Really Works In SEO & Content Marketing
PDF
Storytelling For The Web: Integrate Storytelling in your Design Process
PDF
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Sentiment analysis-by-nltk
Python NLTK
Jsp abes new
Get_vs_Post
Word sense dissambiguation
2024 Trend Updates: What Really Works In SEO & Content Marketing
Storytelling For The Web: Integrate Storytelling in your Design Process
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...

Recently uploaded (20)

PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Classroom Observation Tools for Teachers
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
master seminar digital applications in india
PDF
Computing-Curriculum for Schools in Ghana
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Complications of Minimal Access Surgery at WLH
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Renaissance Architecture: A Journey from Faith to Humanism
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Institutional Correction lecture only . . .
Classroom Observation Tools for Teachers
PPH.pptx obstetrics and gynecology in nursing
master seminar digital applications in india
Computing-Curriculum for Schools in Ghana
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
TR - Agricultural Crops Production NC III.pdf
Insiders guide to clinical Medicine.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
O5-L3 Freight Transport Ops (International) V1.pdf
Cell Types and Its function , kingdom of life
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Ad
Ad

Sentiments Analysis using Python and nltk

  • 1. Twitter Sentiment Analysis using Python and NLTK Presentation by: ASHWIN PERTI, Department of IT
  • 2. Sentiment Analysis using PYTHON The purpose of this Sentiment Analysis is: ● Able to automatically classify a tweet as a positive OR ● Negative tweet Sentiment wise
  • 3. Sentiment Analysis using PYTHON ● The classifier needs to be trained: ● We need a list of manually classified tweets.
  • 4. Positive Tweets ● I love this car ● This view is amazing ● I feel great this morning ● I am so excited about the concert ● He is my best friend
  • 5. Negative Tweets ● I do not like this car ● This view is horrible ● I feel tired this morning ● I am not looking forward to the concert ● He is my enemy
  • 6. Test Tweets ● TEST SET – to assess the exactitude of the trained classifier ● I feel happy this morning. positive ● Larry is my friend. positive ● I do not like that man. negative ● My house not great. negative ● Your song annoying. negative
  • 7. CLASSIFIER ● The list of word features need to be extracted from the tweets. ● It is a list with every distinct words ordered by frequency of appearance.
  • 8. CLASSIFIER – Feature Extractor ● To decide which features are more relevant. ● The one we are going to use returns a dictionary indicating that words are contained in the input passed. ● INPUT - tweet
  • 10. Naive Bayes Classifier ● It uses the prior probability of each label – which is the frequency of each label in the training set and the contribution from each feature. ● In our case, the frequency of each label is the same for 'positive' and 'negative'. ● Word 'amazing' appears in 1 of 5 of the positive tweets and none of the negative tweets. ● This means that the likelihood of the 'positive' label will be multiplied by 0.2 when this word is seen as part of the input.
  • 11. CLASSIFY ● Now that we have our classifier initialized, ● Classify a tweet and ● See what the sentiment type output is: ● Our classifier is able to detect that this tweet has a positive sentiment because ● Of the word 'friend' ● Which is associated to the positive tweet: ● 'He is my best friend'
  • 12. print extract_features(tweet2.split()) ● 'contains(looking)': False, 'contains(feel)': False, ● 'contains(the)': False, ● 'contains(excited)': False, ● 'contains(about)': False, ● 'contains(great)': False, ● 'contains(horrible)': False, ● 'contains(car)': False, ● 'contains(this)': False, ● 'contains(best)': False, ● 'contains(friend)': True, ● 'contains(concert)': False, ● 'contains(forward)': False, ● 'contains(view)': False, ● 'contains(tired)': False, ● 'contains(like)': False, ● 'contains(love)': False, ● 'contains(amazing)': False, ● 'contains(enemy)': False, ● 'contains(not)': True, ● 'contains(morning)': False}