-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.py
executable file
·807 lines (725 loc) · 19.8 KB
/
analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
import pickle
import matplotlib.pyplot as plt
import sys
import MySQLdb
import peewee
import datetime
import time
from peewee import *
import random
import json
import globals
actual_electoral_votes = {
"AL": {
"class": "r",
"votes": 9
},
"AK": {
"class": "r",
"votes": 3
},
"AZ": {
"class": "r",
"votes": 11
},
"AR": {
"class": "r",
"votes": 6
},
"CA": {
"class": "d",
"votes": 55
},
"CO": {
"class": "d",
"votes": 9
},
"CT": {
"class": "d",
"votes": 7
},
"DE": {
"class": "d",
"votes": 3
},
"DC": {
"class": "d",
"votes": 3
},
"FL": {
"class": "d",
"votes": 29
},
"GA": {
"class": "r",
"votes": 16
},
"HI": {
"class": "d",
"votes": 4
},
"ID": {
"class": "r",
"votes": 4
},
"IL": {
"class": "d",
"votes": 20
},
"IN": {
"class": "r",
"votes": 11
},
"IA": {
"class": "d",
"votes": 6
},
"KS": {
"class": "r",
"votes": 6
},
"KY": {
"class": "r",
"votes": 8
},
"LA": {
"class": "r",
"votes": 8
},
"ME": {
"class": "d",
"votes": 4
},
"MD": {
"class": "d",
"votes": 10
},
"MA": {
"class": "d",
"votes": 11
},
"MI": {
"class": "d",
"votes": 16
},
"MN": {
"class": "d",
"votes": 10
},
"MS": {
"class": "r",
"votes": 6
},
"MO": {
"class": "r",
"votes": 10
},
"MT": {
"class": "r",
"votes": 3
},
"NE": {
"class": "r",
"votes": 5
},
"NV": {
"class": "d",
"votes": 6
},
"NH": {
"class": "d",
"votes": 4
},
"NJ": {
"class": "d",
"votes": 14
},
"NM": {
"class": "d",
"votes": 5
},
"NY": {
"class": "d",
"votes": 29
},
"NC": {
"class": "r",
"votes": 15
},
"ND": {
"class": "r",
"votes": 3
},
"OH": {
"class": "d",
"votes": 18
},
"OK": {
"class": "r",
"votes": 7
},
"OR": {
"class": "d",
"votes": 7
},
"PA": {
"class": "d",
"votes": 20
},
"RI": {
"class": "d",
"votes": 4
},
"SC": {
"class": "r",
"votes": 9
},
"SD": {
"class": "r",
"votes": 3
},
"TN": {
"class": "r",
"votes": 11
},
"TX": {
"class": "r",
"votes": 38
},
"UT": {
"class": "r",
"votes": 6
},
"VT": {
"class": "d",
"votes": 3
},
"VA": {
"class": "d",
"votes": 13
},
"WA": {
"class": "d",
"votes": 12
},
"WV": {
"class": "r",
"votes": 5
},
"WI": {
"class": "d",
"votes": 10
},
"WY": {
"class": "r",
"votes": 3
}
}
state_dict = {
"AL": "Alabama",
"AK": "Alaska",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
"DC": "District Of Columbia",
"FL": "Florida",
"GA": "Georgia",
"HI": "Hawaii",
"ID": "Idaho",
"IL": "Illinois",
"IN": "Indiana",
"IA": "Iowa",
"KS": "Kansas",
"KY": "Kentucky",
"LA": "Louisiana",
"ME": "Maine",
"MD": "Maryland",
"MA": "Massachusetts",
"MI": "Michigan",
"MN": "Minnesota",
"MS": "Mississippi",
"MO": "Missouri",
"MT": "Montana",
"NE": "Nebraska",
"NV": "Nevada",
"NH": "New Hampshire",
"NJ": "New Jersey",
"NM": "New Mexico",
"NY": "New York",
"NC": "North Carolina",
"ND": "North Dakota",
"OH": "Ohio",
"OK": "Oklahoma",
"OR": "Oregon",
"PA": "Pennsylvania",
"RI": "Rhode Island",
"SC": "South Carolina",
"SD": "South Dakota",
"TN": "Tennessee",
"TX": "Texas",
"UT": "Utah",
"VT": "Vermont",
"VA": "Virginia",
"WA": "Washington",
"WV": "West Virginia",
"WI": "Wisconsin",
"WY": "Wyoming"
}
database = MySQLDatabase (
'socialnetworkingdb',
**{
'host': '',
'password': '',
'user': ''
}
)
class UnknownField(object):
def __init__(self, *_, **__): pass
class BaseModel(Model):
class Meta:
database = database
class User(BaseModel):
id = CharField(db_column='ID', primary_key=True)
followers_count = IntegerField()
friends_count = IntegerField()
location = CharField(null=True)
name = CharField()
screen_name = CharField()
statuses_count = IntegerField()
verified = IntegerField()
class Meta:
db_table = 'USER'
class Tweet(BaseModel):
id = CharField(db_column='ID', primary_key=True)
created_at = DateTimeField(null=True)
retweet_count = IntegerField()
tweet_text = CharField()
user = ForeignKeyField(db_column='user_id', rel_model=User, to_field='id')
class Meta:
db_table = 'TWEET'
class HashTag(BaseModel):
hashtag = CharField()
tweet = ForeignKeyField(db_column='tweet_id', rel_model=Tweet, to_field='id')
class Meta:
db_table = 'HASHTAG'
indexes = (
(('tweet', 'hashtag'), True),
)
primary_key = CompositeKey('hashtag', 'tweet')
class TweetSentiment(BaseModel):
classification = CharField()
polarity = DecimalField()
tweet = ForeignKeyField(db_column='tweet_id', primary_key=True, rel_model=Tweet, to_field='id')
class Meta:
db_table = 'TWEETSENTIMENT'
class TweetPolitical(BaseModel):
classification = CharField()
democrat_prob = DecimalField()
republican_prob = DecimalField()
third_prob = DecimalField()
tweet = ForeignKeyField(db_column='tweet_id', primary_key=True, rel_model=Tweet, to_field='id')
class Meta:
db_table = 'TWEETPOLITICAL'
def get_maxes(tweet_list):
MAX_RTS = 0
MAX_FOLLOWERS = 0
for tweet in tweet_list:
if tweet.retweet_count > MAX_RTS:
MAX_RTS = tweet.retweet_count
if tweet.followers_count > MAX_FOLLOWERS:
MAX_FOLLOWERS = tweet.followers_count
print('{0} max rts, {1} max followers'.format(MAX_RTS, MAX_FOLLOWERS))
return (MAX_RTS, MAX_FOLLOWERS)
def get_all_tweets(limit):
database.connect()
tweet_query = (Tweet.select(Tweet, TweetPolitical, TweetSentiment, User)
.join(TweetPolitical)
.where(TweetPolitical.tweet == Tweet.id)
.switch(Tweet)
.join(TweetSentiment)
.where(TweetSentiment.tweet == Tweet.id)
.switch(Tweet)
.join(User)
.limit(1000000)
.naive())
results = tweet_query.execute()
database.close()
list_tweets = []
for result in results:
list_tweets.append(result)
return list_tweets
def tweets_with_hashtag_to_labelled(hashtag, label):
database.connect()
tweet_query = (HashTag.select(HashTag, Tweet, TweetPolitical, TweetSentiment, User)
.where(fn.Lower(HashTag.hashtag) == hashtag)
.join(Tweet)
.join(TweetPolitical)
.where(TweetPolitical.tweet == Tweet.id)
.switch(Tweet)
.join(TweetSentiment)
.where(TweetSentiment.tweet == Tweet.id)
.switch(Tweet)
.join(User)
.limit(8000)
.naive())
results = tweet_query.execute()
database.close()
list_tweets = []
for result in results:
list_tweets.append({'text': result.tweet_text, 'label': label})
return list_tweets
def get_tweets_with_hashtag(hashtag, limit):
database.connect()
tweet_query = (HashTag.select(HashTag, Tweet, TweetPolitical, TweetSentiment, User)
.limit(limit)
.where(fn.Lower(HashTag.hashtag) == hashtag)
.join(Tweet)
.join(TweetPolitical)
.where(TweetPolitical.tweet == Tweet.id)
.switch(Tweet)
.join(TweetSentiment)
.where(TweetSentiment.tweet == Tweet.id)
.switch(Tweet)
.join(User)
.naive())
results = tweet_query.execute()
database.close()
list_tweets = []
for result in results:
list_tweets.append(result)
return list_tweets
def get_tweets_nth_row(n, limit):
database.connect()
tweet_query = (Tweet.select(Tweet, TweetPolitical, TweetSentiment, User)
.limit(limit)
.where(Tweet.id % n == 0)
.join(TweetPolitical)
.where(TweetPolitical.tweet == Tweet.id)
.switch(Tweet)
.join(TweetSentiment)
.where(TweetSentiment.tweet == Tweet.id)
.switch(Tweet)
.join(User)
.naive())
results = tweet_query.execute()
database.close()
list_tweets = []
for result in results:
list_tweets.append(result)
return list_tweets
def save_sample_set(days):
sample_tweet_list = []
for k in days:
sample_tweet_list.extend(days[k][0:500])
pickle_tweets(sample_tweet_list[:-500], sample_fname)
def pickle_tweets(tweet_list, fname):
with open(fname, 'wb') as f:
pickle.dump(tweet_list, f)
def unpickle_tweets(fname):
list_tweets = []
with open(fname, 'rb') as f:
list_tweets = pickle.load(f)
return list_tweets
### Tweet Bucket Methods ###
def in_days(tweet_list):
days = {}
for tweet in tweet_list:
key = str(tweet.created_at.date())
if key not in days:
days[key] = []
days[key].append(tweet)
return days
def in_months(tweet_list):
months = {}
for tweet in tweet_list:
key = '{0}-{1}'.format(str(tweet.created_at.month), str(tweet.created_at.year))
if key not in months:
months[key] = []
months[key].append(tweet)
return months
def in_locations(tweet_list):
locations = {}
for tweet in tweet_list:
key = tweet.location
if key not in locations:
locations[key] = []
locations[key].append(tweet)
return locations
def get_normalize_days(tweet_list, tweets_per_day):
days = in_days(tweet_list)
start = time.time()
for k in days:
if len(days[k]) > tweets_per_day :
days[k] = random.sample(days[k], tweets_per_day)
end = time.time()
elapsed = end - start
print('Took {0} to sample {1} tweets per day for {2} days'.format(elapsed, tweets_per_day, len(days)))
return days
def in_states(tweet_list):
#state list as kv pair, state_list[abbrv] = full-state-name
states = {}
for tweet in tweet_list:
for k in state_dict:
if tweet.location is None:
pass
elif k in tweet.location.split() or state_dict[k] in tweet.location:
if k not in states:
states[k] = []
states[k].append(tweet)
return states
### End Bucket Methods ###
### Metrics
def political_lean(pdict, sentiment_polarity):
polit = 1 if (pdict['1'] > pdict['2']) == 1 else -1
prob = abs(pdict['1'] - pdict['2'])
return float(polit) * float(prob)
def togetherness(prob1, prob2, prob3):
return 1 - max(abs(prob1-prob2), abs(prob1-prob3), abs(prob2-prob3))
def weight(tweet, MAX_RTS, MAX_FOLLOWERS):
return (0.35 * tweet.verified +
0.2 * float(tweet.retweet_count/MAX_RTS) +
0.45 * float(tweet.followers_count/MAX_FOLLOWERS))
def day_to_number(day_str):
return int(day_str.replace('-',''))
def percent_positive(tweet_list):
pos_count = 0
for tweet in tweet_list:
if tweet.classification == 'positive':
pos_count+= 1
return float(pos_count/len(tweet_list))
#returns 'r' 'd' or 't'
def pclassification(tweet):
d = {'r': tweet.republican_prob, 'd': tweet.democrat_prob, 't': tweet.third_prob}
return max(d, key=d.get)
def percent_political_classifcation(tweet_list):
rep_count = 0
dem_count = 0
thr_count = 0
for tweet in tweet_list:
classif = pclassification(tweet)
if classif == 'r':
rep_count += 1
elif classif =='d':
dem_count +=1
else:
thr_count +=1
total_tweets = len(tweet_list)
return (float(rep_count/total_tweets), float(dem_count/total_tweets), float(thr_count/total_tweets))
def sentiments(tweet_list):
pos_count = 0
neg_count = 0
neut_count = 0
for tweet in tweet_list:
if tweet.classification == 'positive':
pos_count+= 1
elif tweet.classification == 'negative':
neg_count+=1
else:
neut_count +=1
return (float(pos_count/len(tweet_list)), float(neg_count/len(tweet_list)), float(neut_count/len(tweet_list)))
def percent_political(tweet_list):
rep_probabilities = 0
dem_probabilities = 0
thr_probabilities = 0
for tweet in tweet_list:
rep_probabilities += tweet.republican_prob
dem_probabilities += tweet.democrat_prob
thr_probabilities += tweet.third_prob
total_tweets = len(tweet_list)
return (float(rep_probabilities/total_tweets), float(dem_probabilities/total_tweets), float(thr_probabilities/total_tweets))
#higher negative = higher republican
def political_score(tweet_list, MAX_RTS, MAX_FOLLOWERS):
score = 0
for tweet in tweet_list:
wt = weight(tweet, MAX_RTS, MAX_FOLLOWERS)
sent = -1 if tweet.classification == 'negative' else 1
pclass_mod = 1 if pclassification(tweet) == 'd' else -1
#pprob = tweet.republican_prob if pclass_mod == -1 else tweet.democrat_prob
score += float(wt * sent * pclass_mod)
return float(score/len(tweet_list))
def plot_percent_pclassification_per_day(days):
x = [day_to_number(k) for k in list(days.keys())]
yr = []
yd = []
yt = []
for k in days:
pclasses = percent_political_classifcation(days[k])
yr.append(pclasses[0])
yd.append(pclasses[1])
yt.append(pclasses[2])
fig, ax = plt.subplots()
ax.plot(x, yr, label="Republican")
ax.plot(x, yd, label="Democrat")
ax.plot(x, yt, label="Third Party")
ax.legend(loc='upper right')
plt.xticks(x, [str(xi) for xi in x])
plt.show()
def plot_percent_pclassification_probs_per_day(days):
x = [day_to_number(k) for k in list(days.keys())]
yr = []
yd = []
yt = []
for k in days:
pclasses = percent_political(days[k])
yr.append(pclasses[0])
yd.append(pclasses[1])
yt.append(pclasses[2])
fig, ax = plt.subplots()
ax.plot(x, yr, label="Republican")
ax.plot(x, yd, label="Democrat")
ax.plot(x, yt, label="Third Party")
ax.legend(loc='upper right')
plt.xticks(x, [str(xi) for xi in x])
plt.show()
def plot_percent_positive_per_day(days):
x = [day_to_number(k) for k in list(days.keys())]
y = [percent_positive(days[k]) for k in days]
plt.figure()
plt.plot(range(len(x)), y)
plt.xticks(range(len(x)), [str(xi) for xi in x], rotation = 'vertical')
plt.show()
def plot_togetherness(days):
x = [day_to_number(k) for k in list(days.keys())]
y = []
for k in days:
(rprob, dprob, tprob) = percent_political(days[k])
y.append(togetherness(rprob, dprob, tprob))
plt.figure()
plt.title("Togetherness Metric over time")
plt.plot(range(len(x)), y)
x_strs = [str(xi) for xi in x]
plt.xticks(range(len(x)), x_strs)
plt.show()
def state_analysis(list_tweets):
states = in_states(list_tweets)
state_probs = {}
for k in states:
(rper, dper, tper) = percent_political_classifcation(states[k])
d = {'r': rper, 'd': dper, 't': tper}
classif = max(d, key=d.get)
state_probs[k] = {'r': rper, 'd': dper, 't': tper, 'class': classif}
num_incorrect = 0
electoral_votes_incorrect = 0
for k in states:
if actual_electoral_votes[k]['class'] != state_probs[k]['class']:
num_incorrect+= 1
electoral_votes_incorrect += actual_electoral_votes[k]['votes']
print('State {0} incorrect, rep_prob: {1}, dem_prob: {2}'.format(k, state_probs[k]['r'], state_probs[k]['d']))
accuracy = 1 - float(num_incorrect/len(states))
accuracy_electoral = float((538-electoral_votes_incorrect)/538)
print('Model State Electoral Vote Prediction Accuracy by Votes: {0}, {1}/538 votes correct'.format(accuracy_electoral, 538-electoral_votes_incorrect))
print('Model State Electoral Vote Prediction Accuracy by States: {0}, {1}/{2} states correct'.format(accuracy, len(states)-num_incorrect, len(states)))
sort_repub = [k for k in sorted(state_probs, key=lambda s:state_probs[s]['r'], reverse=True)]
sort_dem = [k for k in sorted(state_probs, key=lambda s:state_probs[s]['d'], reverse=True)]
print('10 most republican states: ', sort_repub[0:10])
print('10 most democrat states: ', sort_dem[0:10])
def plot_percent_positve_and_classifications(days):
x = [day_to_number(k) for k in list(days.keys())]
y = [percent_positive(days[k]) for k in days]
yr = []
yd = []
yt = []
for k in days:
pclasses = percent_political_classifcation(days[k])
yr.append(pclasses[0])
yd.append(pclasses[1])
yt.append(pclasses[2])
fig, ax = plt.subplots()
ax.plot(range(len(x)), y, label='Percent Positive')
ax.plot(range(len(x)), yr, label="Republican")
ax.plot(range(len(x)), yd, label="Democrat")
ax.plot(range(len(x)), yt, label="Third Party")
ax.legend(loc='upper right')
plt.xticks(range(len(x)), [str(xi) for xi in x])
plt.show()
plt.show()
def print_tweet(t):
print('User {0} tweeted: {1}'.format(t.screen_name, t.tweet_text))
print('at {0}, with {1} retweets'.format(str(t.created_at), t.retweet_count))
print('{0} has {1} followers, {2} friends, {3} verified'.format(t.screen_name, str(t.followers_count), str(t.friends_count),'is' if t.verified == 1 else 'is not'))
print('p classification {0}, sentiment {1}'.format(pclassification(t), t.classification))
num_tweets = 0
pull_from_db = False
try:
num_tweets = int(sys.argv[1])
if sys.argv[2] == 'pull':
pull_from_db = True
except:
print('Usage: python analysis.py <num_tweets> <pull?>')
exit()
list_tweets = []
fname = 'tweet_list.pickle'
sample_fname = 'sample_tweet_list.pickle'
if pull_from_db:
start = time.time()
list_tweets = get_all_tweets(100)
end = time.time()
elapsed = end - start
print('Took {0} seconds to pull {1} tweets'.format(str(elapsed), len(list_tweets)))
#pickle_tweets(list_tweets, fname)
else:
list_tweets = unpickle_tweets(sample_fname)
# days = get_normalize_days(list_tweets, 10000)
# for k in days:
# print ('Day: {0} has {1} tweets'.format(k, len(days[k])))
# import pickle
# pclasser = pickle.load(open('political_classification/c1.classifier', 'rb'))
# pol_leans = []
# for tweet in list_tweets[500:550]:
# pol_lean = political_lean(pclasser.probs(tweet.tweet_text), tweet.polarity)
# print(tweet.tweet_text)
# print(pol_lean)
# days = in_days(list_tweets)
# plot_percent_positve_and_classifications(days)
#state_analysis(list_tweets)
# days = in_days(list_tweets)
# plot_togetherness(days)
# labeled_tweets = []
# labeled_tweets.extend(tweets_with_hashtag_to_labelled('obama', 1))
# labeled_tweets.extend(tweets_with_hashtag_to_labelled('obama2012', 1))
# labeled_tweets.extend(tweets_with_hashtag_to_labelled('obamabiden', 1))
# print('dem tweets', len(labeled_tweets))
# labeled_tweets.extend(tweets_with_hashtag_to_labelled('romney', 2))
# labeled_tweets.extend(tweets_with_hashtag_to_labelled('romney2012', 2))
# labeled_tweets.extend(tweets_with_hashtag_to_labelled('romneyryan', 2))
# print('full length', len(labeled_tweets))
# #
# with open('labelled.json', 'w') as f:
# json.dump(labeled_tweets, f)
# obama_tweets = get_tweets_with_hashtag('obama', num_tweets)
# romney_tweets = get_tweets_with_hashtag('romneyryan', num_tweets)
# print(romney_tweets[10].tweet_text)
#
# print(percent_political_classifcation(obama_tweets))
# print(sentiments(obama_tweets))
# print(percent_political_classifcation(romney_tweets))
# print(sentiments(romney_tweets))
# (MAX_RTS, MAX_FOLLOWERS) = get_maxes(list_tweets)
#
# sort_by_weight = sorted(list_tweets, key=lambda t: weight(t))
# print_tweet(sort_by_weight[-4])
# print_tweet(sort_by_weight[-5])
# print_tweet(sort_by_weight[-6])
# states = in_states(list_tweets)
# pscores = {}
# (MAX_RTS, MAX_FOLLOWERS) = get_maxes(list_tweets)
#
# for k in states:
# pscores[k] = political_score(states[k], MAX_RTS, MAX_FOLLOWERS)
#
#
# print([(k, pscores[k]) for k in sorted(pscores, key=pscores.get)])
# days = in_days(list_tweets)
# plot_percent_positive_per_day(days)
#state_analysis(list_tweets)
#in_states(list_tweets)
# locs = in_locations(list_tweets)
# for k in locs:
# if len(locs[k]) > 5:
# print ('Location: {0} has {1} tweets'.format(k, len(locs[k])))
#plot_percent_pclassification_per_day(days)
#plot_percent_pclassification_probs_per_day(days)
#plot_percent_positive_per_day(days)