Skip to content

Commit ecf56ba

Browse files
authored
Update TSA Part 7 - Plotting the tweets.py
1 parent b452dff commit ecf56ba

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Section 7 - Twitter Sentiment Analysis/TSA Part 7 - Plotting the tweets.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
with 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
4143
for tweet in list_tweets:
4244
tweet = re.sub(r"^https://t.co/[a-zA-Z0-9]*\s", " ", tweet)
@@ -67,9 +69,20 @@
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()

0 commit comments

Comments
 (0)