-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
executable file
·40 lines (28 loc) · 889 Bytes
/
model.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
import globals
import pickle
import sys
import json
from pprint import pprint
classifier_file = sys.argv[1]
tweets_file = sys.argv[2]
with open(classifier_file, 'rb') as f:
political_classifier = pickle.load(f)
print(political_classifier.classify("This is a fake madeup tweet"))
def load_tweets(fname):
with open(fname,'r') as f:
data = json.load(f)
return data
tweet_list = load_tweets(tweets_file)
def weight_metric(tweet):
verified = tweet['user']['verified']
verified_wt = 0.25
followers = tweet['user']['followers_count']
followers_wt = 0.1
retweets = tweet['retweet_count']
retweets = 0.5
favorites = tweet['user']['favourites']
favorites_wt =
for tweet in tweet_list:
classifcation = political_classifier.classify(tweet['text'])
tweet['classification'] = classification
pprint(classifcation)