-
Notifications
You must be signed in to change notification settings - Fork 19
Turning In Text Mining Project #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,204 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": false | ||
| }, | ||
| "outputs": [ | ||
| { | ||
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "RT @JetBlue: It’s not over yet. Thanks @DavidOrtiz for making your final regular season anything but! #ThanksPapi https://t.co/7wYPVx6oSK (0.06666666666666667, 0.4256410256410256) neutral\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "RT @AirlinesDotOrg: ICYMI: Starting January 5, @JetBlue will have a new cross-country flight from #LAX to #MCO https://t.co/hLT74crUSf (0.06818181818181818, 0.2772727272727273) neutral\n", | ||
| "@JetBlue @Kyratj please @AmericanAir @united @LAN_Ayuda make fun of this airline joke (0.3, 0.2) positive\n", | ||
| "@JetBlue we had a flight conexión, so we'll loose 2 days of work. Who is going to pay for it? By now, no one has a real solution. (0.06153846153846154, 0.2846153846153846) neutral\n", | ||
| ".@JetBlue @Kyratj FYI she's talking about your shitty costumer service and your lack of consern towards your clients (UIO-FFL 2850) (0.0, 0.0) neutral\n", | ||
| "Grateful to the @JetBlue airport crew for a seamless accommodation. All is now forgiven! (Still think the system should be modified though)😀 (0.125, 0.1) positive\n", | ||
| "@JetBlue a flight is cancelled because of a flight attendant. I've lost 2 days of work and no one is giving us any solutions. (0.2, 0.4) positive\n", | ||
| "RT @Kyratj: @jetblue se enferma una azafata y cancelan un vuelo. Qué falta de seriedad. (0.0, 0.0) neutral\n", | ||
| "RT @NickelGalbraith: NOW BOARDING! @JetBlue partnering w/ @autismspeaks to help prepare those with #autism to fly wherever their dreams wil… (0.8, 0.9) positive\n", | ||
| "@jetblue se enferma una azafata y cancelan un vuelo. Qué falta de seriedad. (0.0, 0.0) neutral\n", | ||
| "@JetBlue Terrible servicio. 10 minutos antes de partir cancelan el vuelo. Nos quitan los pasaportes y no dicen nada. https://t.co/a6rHr9znW6 (-1.0, 1.0) negative\n", | ||
| "@JetBlue is flight 2850 departing tonight (Monday) cancelled as well? (0.0, 0.0) neutral\n", | ||
| "@JetBlue my flight (2850) has been cancelled. What are the next steps?! (0.0, 0.0) neutral\n", | ||
| "@JetBlue your prices have gotten out of hand.Booked flight one way mco->bdl $84. Your price same day $140.No bags. @SouthwestAir 2 bags FREE (0.2, 0.4625) positive\n", | ||
| "@JetBlue Customer Service for the Win!!\n", | ||
| "Had booking issue. Called in and solved in < 15 min :) (0.75, 0.7) positive\n", | ||
| "@JetBlue I would like to know on Oct 4th if the trip from Haiti to USA is canceled till October 5th. Please I want to know If confirmed. (0.4, 1.0) positive\n", | ||
| "Made it back from Jamaica safe before the hurricane thanks to @JetBlue. Literally on the last flight leaving the island! (0.175, 0.19166666666666665) positive\n", | ||
| "@JetBlue an enjoyable trip flight 624 from LAX to JFK. Shout out to Lovell and Meisha (0.5, 0.6) positive\n", | ||
| "Please be Advised of Hurricane Matthew - Central Caribbean Travel alerts for @JetBlue https://t.co/IWNa0B0tQV (0.0, 0.25) neutral\n", | ||
| "RT @TheSleepyElite: Inside @JetBlue’s Quest to Make Plane Food Great Again \n", | ||
| "#travel @WIRED https://t.co/CMB8fzZU0s (0.8, 0.75) positive\n", | ||
| "@JetBlue thanks, you guys are the best social team in the business! (0.4138888888888889, 0.18888888888888888) positive\n", | ||
| "RT @SecretFlying: New York to Antigua, Antigua and Barbuda for only $293 roundtrip with @JetBlue\n", | ||
| "\n", | ||
| "https://t.co/32NpsKsE4f https://t.co/7dtM… (0.06818181818181818, 0.7272727272727273) neutral\n", | ||
| "RT @davidortiz: U want 2 throw the first pitch at a @RedSox game or go to Spring Training? check the @JetBlue’s auction #BidforGood https:/… (-0.07500000000000001, 0.3666666666666667) neutral\n", | ||
| "@JetBlue heard weather's bad at SLC. Any expected changes to flt 801 out of MCO? (-0.3999999999999999, 0.5333333333333333) negative\n", | ||
| "RT @davidortiz: U want 2 throw the first pitch at a @RedSox game or go to Spring Training? check the @JetBlue’s auction #BidforGood https:/… (-0.07500000000000001, 0.3666666666666667) neutral\n", | ||
| "@NickelGalbraith @JetBlue @autismspeaks @AngelasClues bring back the #BluesClues play area @ JFK! #autism #wow\n", | ||
| "https://t.co/qQmxIvh87H (0.05, 0.5) neutral\n", | ||
| "@JetBlue why am I still in Boston?! My 10pm flight should have landed in NYC by now. #nosleep #willbelatetoworktomorrow (0.0, 0.0) neutral\n", | ||
| "RT @NickelGalbraith: NOW BOARDING! @JetBlue partnering w/ @autismspeaks to help prepare those with #autism to fly wherever their dreams wil… (0.8, 0.9) positive\n", | ||
| "In order to use @JetBlue #FamilyPooling, I need unique email addresses for everyone in family, including my 2 four yr olds. #TrueBlueFail (0.375, 1.0) positive\n", | ||
| "RT @JetBlue: #ClimateChange is a thing. And so is renewable jet fuel. See how we’re lowering emissions. https://t.co/hVUg9P9HJR https://t.c… (0.0, 0.0) neutral\n", | ||
| "RT @JetBlue: You had us at beignets. Get your fix w/ nonstop service btwn MSY & FLL: https://t.co/WpQJM9gU0h #DestinationFriday https://t.c… (0.0, 0.0) neutral\n", | ||
| "Thanks @JetBlue just had great customer service! #AppreciateYou (0.6, 0.475) positive\n", | ||
| "RT @JetBlue: It’s not over yet. Thanks @DavidOrtiz for making your final regular season anything but! #ThanksPapi https://t.co/7wYPVx6oSK (0.06666666666666667, 0.4256410256410256) neutral\n", | ||
| "Thanks for the delay notification email 5 min before takeoff @JetBlue. #nothelpful https://t.co/FntKLBb5pY (0.2, 0.2) positive\n", | ||
| "@JetBlue just messaged it to you. (0.0, 0.0) neutral\n", | ||
| "...just remembering how weird it was flying @JetBlue last week without teddy grahams. craisins are a viable alternative, I suppose. :P (0.08333333333333333, 0.6888888888888888) neutral\n", | ||
| "@JetBlue The real question is - how do you get bumped up to Mint if there are empty seats? (0.05, 0.4) neutral\n", | ||
| "Going To Grenada? @JetBlue Adding More #Travel Options - https://t.co/NuuQmerJtA (subscription) : https://t.co/KD653ndgji (0.5, 0.5) positive\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "RT @SecretFlying: New York to Antigua, Antigua and Barbuda for only $293 roundtrip with @JetBlue\n", | ||
| "\n", | ||
| "https://t.co/32NpsKsE4f https://t.co/7dtM… (0.06818181818181818, 0.7272727272727273) neutral\n", | ||
| ".@united the difference between your brand & companies like @jetblue is they'd do more than offer weak apology for… https://t.co/vSk7M9Bj8p (0.0625, 0.5625) neutral\n", | ||
| "It's the little things that make the difference...@JetBlue has mastered the art of customer service. (-0.1875, 0.5) negative\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs the game is a MESS!! #chiefsnation (-0.33671875, 0.2875) negative\n", | ||
| "@JetBlue Quesrion-how do I know if my ticket is Blue, Blue Plus or Flex? It says no where on my flight info. I didn't purchase ticket. (0.0, 0.1) neutral\n", | ||
| "@mefan4life_m @metheridge @JetBlue @DIRECTV @Chiefs yea it ain't pretty. (-0.125, 1.0) negative\n", | ||
| "@tracykate24 @metheridge @JetBlue @DIRECTV @Chiefs I have to look away, it's brutal to watch. 🏈☹️ (-0.875, 1.0) negative\n", | ||
| "@JetBlue disappointed in last min plane change, seat switch and move to back of the plane... How do we get a refund for our Even More seats? (-0.0625, 0.32916666666666666) neutral\n", | ||
| "@JetBlue looking forward to my 5 hour flight after the 1.5 hours we spent on the tarmac especially in my non-reclining seat I didn't book! (-0.05, 0.55) neutral\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs don't count them out yet they have come from behind before with some great finals.#go Chiefs (0.2, 0.725) positive\n", | ||
| "This is internet ....or cyber torture @JetBlue @JFK_IntAirport please let me pay for real service so I don't go insane (-0.4, 0.65) negative\n", | ||
| "Thanks for showing on ur site that my seat didn't recline @JetBlue! Oops, you only did that for some of the non rec… https://t.co/A3VDZsiZHZ (0.125, 0.6) positive\n", | ||
| "RT @AnndiMcAfee: 1st flight delayed 3 1/2 hours return flight plane change seats all messed up- for 50 min flight. No Bueno @JetBlue (0.0, 0.0) neutral\n", | ||
| "1st flight delayed 3 1/2 hours return flight plane change seats all messed up- for 50 min flight. No Bueno @JetBlue (0.0, 0.0) neutral\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs whoop whoop go STEELERS (0.0, 0.0) neutral\n", | ||
| "@JetBlue and thanks! (0.25, 0.2) positive\n", | ||
| "@JetBlue I wish I had caught their names, but great attendants JFK➡️BTV early Friday AM and BTV➡️JFK ~ 9:30 this AM. (0.45, 0.525) positive\n", | ||
| "RT @AirlinesDotOrg: ICYMI: Starting January 5, @JetBlue will have a new cross-country flight from #LAX to #MCO https://t.co/hLT74crUSf (0.06818181818181818, 0.2772727272727273) neutral\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs Steelers (0.0, 0.0) neutral\n", | ||
| "RT @everywhereJRis: Dear @JetBlue What is the point of checking in for a flight online, when the flight has the jetway pulled away :20 min… (0.0, 0.0) neutral\n", | ||
| "Shoutout to @JetBlue for great service all weekend with my knee scooter and broken leg/ankle. Patient, kind team that took great care! ✈️💙 (0.5, 0.7) positive\n", | ||
| "@JetBlue I'm so excited to fly with you guys to Fort Myers this December! (0.6875, 0.825) positive\n", | ||
| "@JetBlue just had to pay for bag via app while checking in. How can I get a receipt for that? (0.0, 0.0) neutral\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs have a great flight. (0.8, 0.75) positive\n", | ||
| "RT @KeithlyBram: .@jetblue was no help since I booked through @Expedia & #Expedia is declining my refund even though I paid for insurance!… (0.0, 0.0) neutral\n", | ||
| "As if @JetBlue wasn't amazing enough, we were treated to a spectacular sunset on our way home. #SoFly https://t.co/FjF97BGsD4 (0.09999999999999998, 0.7666666666666666) neutral\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "RT @haleyhaverkamp: Three hours and counting.... @JetBlue (0.0, 0.0) neutral\n", | ||
| "@metheridge @chiefs @directv @jetblue sorry kiddo. (-0.5, 1.0) negative\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "RT @LBRestaurantWk: Our #SELFoodie winner enjoying her @JetBlue get away at @ArcherHotel #NYC thanks to @GrunionGazette #congrats https://t… (0.35, 0.4) positive\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "@metheridge @JetBlue @DIRECTV We're watching too. Come on @Chiefs! It's only the first quarter...they will come back. #IKnowIt (0.08333333333333333, 0.4444444444444444) neutral\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs longway to go yet :-) (0.5, 1.0) positive\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs It's just the 1sr Q. We can do it!! #GoChiefs (0.0, 0.0) neutral\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs was rough day at the Jets game tda https://t.co/qikdvB3vg8 (-0.25, 0.4) negative\n", | ||
| "RT @metheridge: So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "@metheridge @JetBlue @DIRECTV @Chiefs something has to change.... (0.0, 0.0) neutral\n", | ||
| "So glad @JetBlue has @DIRECTV on board. Not so glad at how @Chiefs are doing right now. Come on #ChiefsKingdom!! (0.48214285714285715, 0.8452380952380952) positive\n", | ||
| "Two hour delay due to a staff signoff error and somehow it takes 40 minutes to load the baggage carousel.. @JetBlue a nightmare as usual (-0.1875, 0.3125) negative\n", | ||
| "@JetBlue Airways Corporation (NASDAQ:JBLU) Short-term Price Target in Focus - Recall News : https://t.co/obIksU2Cn7 (0.0, 0.0) neutral\n", | ||
| "@Jetblue these delays are really an inconvenience FLL to LGA (0.2, 0.2) positive\n", | ||
| "Long line for take off? @JetBlue ... we're already 30 minutes late . Terrible luck with flights this trip 😒 (-0.45, 0.6666666666666666) negative\n", | ||
| "RT @ZookBOS: Thanks to B6 JFK F.O. Alex Devito for the ride today! #732dAirliftSq #McGuireAFB #VetsinBlue #thankaVet @JetBlue https://t.co/… (0.25, 0.2) positive\n", | ||
| "@Delta your airline sucks!!! I took a short flight to SFO or LAS via @JetBlue & they still offered free beverage. U don't! (-0.028645833333333332, 0.4666666666666666) neutral\n", | ||
| "Very grateful shout out to @JetBlue whose staff found latest electronic device my 12yo left on a plane. They called & are shipping it home. (0.2333333333333333, 0.39999999999999997) positive\n", | ||
| "RT @mrcharliemorton: go to San Diego and see my half sister I have not seen for over 20 years! @JetBlue #FlyingItForward (-0.20833333333333331, 0.16666666666666666) negative\n", | ||
| "@JetBlue I thought so, I just didn't want to get stuck at Montego Bay airport. Are you not concerned about hurricane Matthew in Jamaica? (0.0, 0.0) neutral\n", | ||
| "@JetBlue thanks for answering (0.2, 0.2) positive\n", | ||
| "@JetBlue Great choice of music in Terminal 5 JFK, esp @coldplay (0.8, 0.75) positive\n", | ||
| "@JetBlue can you tell me when flight number 560 scheduled to depart from Kingston JA will be reschedule? (0.0, 0.0) neutral\n", | ||
| "@JetBlue Airways Corporation (NASDAQ:JBLU) – Broker Update - NewsDen : https://t.co/LYITm16FOE (0.0, 0.0) neutral\n", | ||
| "@JetBlue Flight number B6 1722 thank you! (0.0, 0.0) neutral\n", | ||
| "@JetBlue I want to thank you for your quick response and help on a delayed flight on Saturday. We appreciate the service! (1 of 2) (0.41666666666666663, 0.5) positive\n", | ||
| "@JetBlue Could you please confirm if my flight from Fort Lauderdale to Montego Bay Jamaica tomorrow hasn't been canceled? Fly 327 #Hurricane (0.8, 0.9) positive\n", | ||
| "@JetBlue Can you please confirm my flight from Montego Bay Jamaica tomorrow at 3 pm has not been canceled? Seems odd given the hurricane. (-0.16666666666666666, 0.25) negative\n", | ||
| "RT @CaseyNeistat: hey @JetBlue $12.99 for a to go wrap feels like gauging. at JFK. just wanted to share https://t.co/PHVIZZ0cTh (0.0, 0.0) neutral\n", | ||
| "Customer service @Jetblue @MCO A+ today (0.0, 0.0) neutral\n", | ||
| "the number of tweets that have a positive sentiment is 41 or 41.0 %\n", | ||
| "the number of tweets that have a neutral sentiment is 46 or 46.0 %\n", | ||
| "the number of tweets that have a negative sentiment is 13 or 13.0 %\n" | ||
| ] | ||
| } | ||
| ], | ||
| "source": [ | ||
| "#$ sudo pip install pattern \n", | ||
| "#$ sudo pip install matplotlib\n", | ||
| "\n", | ||
| "from pattern.web import Twitter\n", | ||
| "from pattern.en import sentiment\n", | ||
| "from matplotlib import numpy as np\n", | ||
| "import matplotlib.pyplot as plt\n", | ||
| "\n", | ||
| "def sent_analysis(company, n):\n", | ||
| " count_total = 0.0\n", | ||
| " count_positive = 0\n", | ||
| " count_neutral = 0\n", | ||
| " count_negative = 0\n", | ||
| " for tweet in Twitter().search(company, count = n):\n", | ||
| " count_total = count_total + 1\n", | ||
| " sent = sentiment(tweet.text)\n", | ||
| " print tweet.text, sent,\n", | ||
| " if sent[0] > 0.1:\n", | ||
| " print 'positive'\n", | ||
| " count_positive = count_positive + 1\n", | ||
| " elif -0.1 < sent[0] < 0.1:\n", | ||
| " print 'neutral'\n", | ||
| " count_neutral = count_neutral + 1\n", | ||
| " else:\n", | ||
| " print 'negative'\n", | ||
| " count_negative = count_negative + 1\n", | ||
| " percent_positive = (count_positive/count_total)*100\n", | ||
| " percent_neutral = (count_neutral/count_total)*100\n", | ||
| " percent_negative = (count_negative/count_total)*100\n", | ||
| " print 'the number of tweets that have a positive sentiment is', count_positive, 'or', percent_positive, '%'\n", | ||
| " print 'the number of tweets that have a neutral sentiment is', count_neutral, 'or', percent_neutral, '%'\n", | ||
| " print 'the number of tweets that have a negative sentiment is', count_negative, 'or', percent_negative, '%'\n", | ||
| " #code for bar graph below using matplotlib python package\n", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good coding practice to put a line of whitespace between parts of code that do different things. This is helpful visually for a reader. I'd suggest a newline before this comment and also maybe before the for loop above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another alternative is to split this into two functions. One is |
||
| " x_axis = ('Positive', 'Neutral', 'Negative')\n", | ||
| " y_axis = np.arange(len(x_axis))\n", | ||
| " count_sent = [count_positive, count_neutral, count_negative]\n", | ||
| " plt.title('Sentiment Analysis Type BreakDown')\n", | ||
| " plt.xticks(y_axis, x_axis)\n", | ||
| " plt.ylabel('Count of Tweets')\n", | ||
| " plt.bar(y_axis, count_sent, align = 'center')\n", | ||
| " plt.show()\n", | ||
| "\n", | ||
| "sent_analysis('@JetBlue', 100)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "metadata": { | ||
| "collapsed": true | ||
| }, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "Python 2", | ||
| "language": "python", | ||
| "name": "python2" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 2 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython2", | ||
| "version": "2.7.6" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 1 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These three lines above can be outside of the for loop. You're overriding them each time and then doing nothing with the result until after the for loop