File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 3636with open ('tfidfmodel.pickle' ,'rb' ) as f :
3737 tfidf = pickle .load (f )
3838
39- sent_tweets = []
39+ total_pos = 0
40+ total_neg = 0
41+
4042# Preprocessing the tweets and predicting sentiment
4143for tweet in list_tweets :
4244 tweet = re .sub (r"^https://t.co/[a-zA-Z0-9]*\s" , " " , tweet )
6769 tweet = re .sub (r"^[a-z]\s+" ," " ,tweet )
6870 tweet = re .sub (r"\s+" ," " ,tweet )
6971 sent = classifier .predict (tfidf .transform ([tweet ]).toarray ())
70- sent_tweets .append (sent )
72+ if sent [0 ] == 1 :
73+ total_pos += 1
74+ else :
75+ total_neg += 1
7176
7277# Visualizing the results
73- plt .plot (sent_tweets )
74- plt .y_label ('sentiment' )
75- plt .show ()
78+ import matplotlib .pyplot as plt
79+ import numpy as np
80+ objects = ['Positive' ,'Negative' ]
81+ y_pos = np .arange (len (objects ))
82+
83+ plt .bar (y_pos ,[total_pos ,total_neg ],alpha = 0.5 )
84+ plt .xticks (y_pos ,objects )
85+ plt .ylabel ('Number' )
86+ plt .title ('Number of Postive and NEgative Tweets' )
87+
88+ plt .show ()
You can’t perform that action at this time.
0 commit comments