Presidential Debate Twitter Sentiment Analysis using Python and NLTK

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024
  • Imagine you’ve got customer review.
    Working out whether it’s a good or bad review is pretty easy right?
    You, read it, then you get a ‘feel’ for whether it’s good or bad.
    Well, now imagine you have 500 review, or 5,000 or even 5 million.
    Getting through all of these and working out which of them is REALLY bad or REALLY good is a whole lotta work. This is where sentiment analysis comes in. It allows you to leverage natural language processing to help speed up this process and work out whether something is good or bad. And because you’re able to do it using code…you can do it FAST. In this video you’ll get to do just that. You’ll learn how to apply sentiment analysis to the #PresidentialDebate Twitter feed in order to calculate overall sentiment (positive or negative) for each presidential candidate.
    In this video you’ll learn how to:
    1. Setting up Twitter Dev
    2. Querying #PresidentialDebate tweets from Twitter using Python
    3. Using NLTK and TextBlob to calculate sentiment
    When using TextBlob for sentiment analysis, you’re able to extract polarity and subjectivity. Polarity refers to how positive or negative something is with the range extending from -1 (negative) to 1 (positive). Subjectivity refers to how much a piece of text is based on emotion with 0 being the least subjective and 1 being the most subjective.
    Sentiment Analysis can also (and is typically) used for:
    * Market research
    * Customer feedback
    * Financial markets analysis
    Note: All content, ideas and opinions are my own!
    GitHub:
    github.com/nic...
    Resources Listed:
    Twitter Developer: / apps
    Twepy: www.tweepy.org/
    NLTK: www.nltk.org/
    Pandas: pandas.pydata....
    Oh, and don't forget to connect with me!
    LinkedIn: / nicholasr. .
    Facebook: / nickrenotte
    GitHub: github.com/nic...
    Happy coding!
    Nick
    P.s. Let me know how you go and drop a comment if you need a hand!
    Technology vector created by freepik - www.freepik.com

ความคิดเห็น • 81

  • @grahamwalker512
    @grahamwalker512 4 ปีที่แล้ว +2

    Great video! Always great to see a tutorial that uses current events to make it "real". Keep up the great work.

    • @NicholasRenotte
      @NicholasRenotte  4 ปีที่แล้ว

      @Graham Walker! Yes, definitely! Trying to keep it relevant and a little bit fun as well.

    • @hectortobias8840
      @hectortobias8840 3 ปีที่แล้ว

      instablaster

  • @gabrielfreay
    @gabrielfreay 3 ปีที่แล้ว +1

    You are the Best, I supposed to be sleeping 😴 but I prefer being watching your videos. Seriously 😳 it's amazing how easy you make things looks like.

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      Ayyyee! So pumped you're enjoying it.

  • @nishadseeraj7034
    @nishadseeraj7034 3 ปีที่แล้ว +3

    Great tutorial! i love your teaching style and how you explain everything as well as the great flow of your video! Looking forward to more python tutorials. I'm new to python having most of my prior experience in R

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      Awesome stuff @Nishad! Welcome to the fam!

  • @anukarthika4ever
    @anukarthika4ever 3 ปีที่แล้ว +2

    Love your content! Condensed and to the point👍👍

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      Thanks so much @Anu! Glad you enjoyed it!

  • @vipinsainilol
    @vipinsainilol 3 ปีที่แล้ว +2

    I appreciate you for making this video!...a great help to learn sentiment analysis

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      Thanks so much @Vipin! Glad you liked it!

  • @pantsuslayer8631
    @pantsuslayer8631 4 ปีที่แล้ว +1

    Thanks, i learned a lot;. Thought im just starting and couldn´t understand every single thing i got the basic idea. please keep making this type of videos!

    • @NicholasRenotte
      @NicholasRenotte  4 ปีที่แล้ว

      👏 awesome, thank you soo much @Pantsu Slayer! If there’s anything you want me to dive deeper into, let me know! Plenty more videos coming 👨‍💻!

  • @sakethgupta2885
    @sakethgupta2885 3 ปีที่แล้ว +1

    underrated channel

  • @Tourismmj
    @Tourismmj 2 ปีที่แล้ว +1

    Thank you so much for sharing the great tutorial, Nick!!!!

  • @musicpatron1693
    @musicpatron1693 3 ปีที่แล้ว +1

    YOUUUUU ARREEE TOOOO FASTTTTT FOR MEEE!!! GOOD JOB!

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      Thanks sooo much! Glad you enjoyed it. Check out the code in the description as well!

  • @christophercrager1925
    @christophercrager1925 2 ปีที่แล้ว

    You make it look so easy. Thank you for sharing!

  • @ashleysami1640
    @ashleysami1640 4 ปีที่แล้ว +2

    Only you could make the debate about Pizza 😂. Where's that #Dominos sponsorship at?
    #nickforpizzapresident

    • @NicholasRenotte
      @NicholasRenotte  4 ปีที่แล้ว +1

      🤷🏾‍♂️ I’m with you @Ashley Sami! #Dominos hit me up! 🤣

  • @princevladimierdelosreyes2025
    @princevladimierdelosreyes2025 3 ปีที่แล้ว +1

    this is a great help. thanks! i subscribed

  • @meeramaurya7670
    @meeramaurya7670 3 ปีที่แล้ว +1

    Great Video, clear explanation..thanks a lot

  • @closed252
    @closed252 3 ปีที่แล้ว +1

    Great Video!!!! Thank you so much for that!

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      Thanks so much @Diego, glad you enjoyed it!

  • @mihaelbos
    @mihaelbos ปีที่แล้ว

    Which sentiment library/tool/model do you recommend for analyzing customer reviews? It tried using vader, bert, roberta, textblob...so far bert was the most accurate.

  • @wilsonwilson137
    @wilsonwilson137 2 ปีที่แล้ว

    Hey, great videos!

  • @yeancahogundipe268
    @yeancahogundipe268 ปีที่แล้ว

    Please How do we balance the dataset ?Great tutorial btw!

  • @ademhilmibozkurt7085
    @ademhilmibozkurt7085 ปีที่แล้ว

    thank you so much

  • @nitinluthra1751
    @nitinluthra1751 2 ปีที่แล้ว

    Dear Nicholas, thank you for this very helpful and condensed video. I am completely new to coding so please answer this novice question. How does one get to the Jupyter Debate Analyser page (before you begin all your analysis)? Until now I have been following Visual Code Studio so this is new for me.

    • @ralphumo7152
      @ralphumo7152 ปีที่แล้ว

      Its just a regular Jupyter page. He named it as "Debate Analyser". Hence you have the Jupyter logo beside the page name.

  • @ghosthanded
    @ghosthanded 2 ปีที่แล้ว

    I keep getting the error TypeError: expected string or bytes-like object when I apply the cleaning functions

  • @bronsonranga5770
    @bronsonranga5770 4 ปีที่แล้ว +4

    Vote pineapples hahah crack up

    • @NicholasRenotte
      @NicholasRenotte  4 ปีที่แล้ว

      🤣 #PepperoniLife for days @Bronson Ranga!!

  • @iTzDharma
    @iTzDharma ปีที่แล้ว

    Update 04.01.2023 Change this:
    tweets = [{"Tweets":tweet.text, "Timestamp":tweet.created_at} for tweet in query]
    with
    tweets = [{"Tweets":tweepy.Tweet.text, "Timestamp":tweepy.Tweet.created_at} for tweet in query]

  • @MeetMoyele
    @MeetMoyele 2 ปีที่แล้ว

    Thank you for the guidance. How much tweets can I retrieve from Twitter?

  • @abdullahbutt1800
    @abdullahbutt1800 3 ปีที่แล้ว

    Great video Nicholas! I'm struggling to put a condition where I want to get tweets from a specific time period. can you please guide me through it. Thanks!

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      Definitely you can apply a filter like so df[df['Timestamp']=='your period']

  • @kartikyadav7421
    @kartikyadav7421 2 ปีที่แล้ว

    Twitter error response: status code = 403; whenever i try to run the tweets command in the beginning

  • @hemalshah1410
    @hemalshah1410 2 ปีที่แล้ว +1

    Hi Nic , while trying to perform -- tweets = [{'Tweet':tweet.text, 'Timestamp':tweet.created_at} for tweet in query] -- the line gives Twitter error response: status code = 403 . What could be reason ? I am having essential access on my twitter Dev account. any Help appreciated.

    • @sricharangovindolla7044
      @sricharangovindolla7044 2 ปีที่แล้ว

      mine too! same problem

    • @hemalshah1410
      @hemalshah1410 2 ปีที่แล้ว +1

      @@sricharangovindolla7044 I figured this is due to lack of permissions on your Twitter dev account. You need to get elevated access.

    • @sricharangovindolla7044
      @sricharangovindolla7044 2 ปีที่แล้ว

      @@hemalshah1410 Ho ok thanks for sharing the information.

    • @Megtheanalyst_
      @Megtheanalyst_ 2 ปีที่แล้ว

      @@hemalshah1410 I Was Approved Of Elevated Access But I Got An Error On That Code 🥹

  • @nwh9926
    @nwh9926 2 ปีที่แล้ว

    Hi , I have problem on applying verification from twitter, this have been a second time because first application have been rejected. Any tips to avoid from been rejected? My project is for my final year project T.T which is for academic purpose T.T it's really important

  • @explorenations892
    @explorenations892 2 ปีที่แล้ว

    what if we want to create a flag for multiple references ??

  • @dwikiahmamaulana2176
    @dwikiahmamaulana2176 3 ปีที่แล้ว +1

    excuse me sir, what kind of method is used for this tutorial ?

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      Heya @Dwiki, it's using the native sentiment method from TextBlob I don't believe they go into much detail as to how it works though: textblob.readthedocs.io/en/dev/api_reference.html#textblob.blob.TextBlob.sentiment

  • @kwabsbotwe6124
    @kwabsbotwe6124 3 ปีที่แล้ว

    To identify the subject from 15:20 onwards how do you differentiate a subject that has both Biden and Trump?

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      Heya @kwabs, you can do that from step four, instead of identifying a single candidate. You can filter on tweets that mention both like so:
      Old code:
      df[df['Biden']==1][['Biden','polarity','subjectivity']].groupby('Biden').agg([np.mean, np.max, np.min, np.median])
      New code:
      df[(df['Biden']==1) and (df['Trump']==1)][['Biden','polarity','subjectivity']].groupby('Biden').agg([np.mean, np.max, np.min, np.median])

    • @kwabsbotwe6124
      @kwabsbotwe6124 3 ปีที่แล้ว +1

      @@NicholasRenotte thanks 🙏

    • @kwabsbotwe6124
      @kwabsbotwe6124 3 ปีที่แล้ว +1

      In situations where you want to know the general political sentiments of the country over a period of time what are the factors to consider in your analysis?

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      @@kwabsbotwe6124 anytime amigo!!

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      @@kwabsbotwe6124 great question, although I wouldn't set out with too many pre-conceived notions as to what the factors might be. This is where exploratory data analysis, clustering and topic modelling come in handy to allow you to determine these factors.

  • @nikhilshetty1212
    @nikhilshetty1212 3 ปีที่แล้ว

    Hey bro Nicholas, I have downloaded a year's data on breast cancer awareness, and now I want to perform a sentiment analysis on it. Will this method be able to process those tweets?

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      Sure will! Just get it into a dataframe and it should be relatively the same process!

    • @nikhilshetty1212
      @nikhilshetty1212 3 ปีที่แล้ว +1

      @@NicholasRenottebrother I'm stuck in the preprocessing step please help err says : 'float' object has no attribute 'replace'

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      @@nikhilshetty1212 sounds like it's trying to update a number instead of a string. Are you processing on a number based column or a string?

    • @nikhilshetty1212
      @nikhilshetty1212 3 ปีที่แล้ว +1

      @@NicholasRenotte string. Actually It would be so great if I could share the issue pic with you

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      @@nikhilshetty1212 jump on the Discord server and shoot it through to me!

  • @voiceofheart9873
    @voiceofheart9873 3 ปีที่แล้ว

    Could you please tell me how to calculate positive , negative and neutral tweets ?

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      All covered in the video 😊!

    • @voiceofheart9873
      @voiceofheart9873 3 ปีที่แล้ว

      @@NicholasRenotte how can i visualize positive, negative and neutral for each individual with bar chart graph?

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      @@voiceofheart9873 try taking a look at the matplotlib package, there is example with a line graph shown towards the end of the video.

    • @voiceofheart9873
      @voiceofheart9873 3 ปีที่แล้ว

      @@NicholasRenotte Thanks for your valuable information sir. Could you please give your Email for contact with you?

    • @voiceofheart9873
      @voiceofheart9873 3 ปีที่แล้ว

      @@NicholasRenotte Please make tutorial about Twitter new feature Covid-19 stream for sentiment analysis.

  • @musicpatron1693
    @musicpatron1693 3 ปีที่แล้ว +2

    hahah you act like getting a developer account is easy...i'm a student and i am not makign an app..it took like a volleying of discussions for a couple days to get a twitter account.. you have to specifically indicate literally what you're doing.

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      FR? I honestly managed to breeze through it, although my explanation was a little different to what I actually ended up using it for 😬

    • @musicpatron1693
      @musicpatron1693 3 ปีที่แล้ว +2

      @@NicholasRenotte i'm just saying, cuz some people might need to know they need to be very literal about what they're using it for..they didn't initially accept my "I'm using it for a school project to do sentiment analysis on Donald Trump's tweets" ...they wanted more info than that. it was frustrating.

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว

      @@musicpatron1693 ah got it, did you end up getting it in the end though?

    • @musicpatron1693
      @musicpatron1693 3 ปีที่แล้ว +1

      @@NicholasRenotte yessir!

    • @NicholasRenotte
      @NicholasRenotte  3 ปีที่แล้ว +1

      @@musicpatron1693 yessss! Awesome work!