1 / 12

Comparing Brand Rivalries

Comparing Brand Rivalries. Download from course website: data (then extract it) 3-4Starter.py. Which one of them is the most heated competition? . Idea. Look at tweets that talk about them See which pair is mentioned together most frequently

nerita
Download Presentation

Comparing Brand Rivalries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Comparing Brand Rivalries Download from course website: data (then extract it) 3-4Starter.py

  2. Which one of them is the most heated competition?

  3. Idea • Look at tweets that talk about them • See which pair is mentioned together most frequently • Belligerence score = # of times mentioned together / # of times either is mentioned • Attention score = # of times mentioned together / # of hours during which they are mentioned

  4. Look at 3-4Starter.py • Mark (using comments) places where you do not understand / haven't seen before • We'll discuss them in a minute

  5. while loop • We've seen for-loop • Here's another way of looping: while (some condition that evaluates to Boolean) : do something • The 'do something' part will be executed again and again until the condition becomes false.

  6. Using while-loop to iterate structured data myList = [1,4,6,3,8,4,0] index = 0 while (index != len(myList)): print(myList[index]) index += 1 • How do you rewrite it using a for-loop? (two ways)

  7. Now you have a way of breaking your computer import random myList = [] while True: myList += [random.random()] • What does it do?

  8. Print meaningful things in your program • Helps debugging • Helps showing progress • Print indicating texts along with values you are interested in.

  9. Finding out Belligerence Score • Belligerence score = # of times mentioned together / # of times either is mentioned • Algorithm • Set a count (# of times mentioned together), 0 intially • For each tweet: • text  look up its text • cokeMentioned  True if 'coke' is in text, False otherwise • pepsiMentioned  True if 'pepsi' is in text, False otherwise • if both cokeMentioned and pepsiMentioned are True • increase count by 1 • Divide count by total number of tweets, print answer

  10. How to find out • if 'coke' appears in some text? • Regular expression! • re.findall(pattern, string) • What the pattern should be?

  11. Finding out Attention Score • Attention score = # of times mentioned together / # of hours during which they are mentioned • How to find out the denominator?

  12. Repeat this • for the personal computer war • for the smartphone war

More Related