SlideShare ist ein Scribd-Unternehmen logo
1 von 12
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}

Weitere ähnliche Inhalte

Kürzlich hochgeladen

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Kürzlich hochgeladen (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

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}