-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsentimentanalysis.py
More file actions
52 lines (40 loc) · 1.29 KB
/
Copy pathsentimentanalysis.py
File metadata and controls
52 lines (40 loc) · 1.29 KB
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
import csv
import string
import numpy as np
import matplotlib.pyplot as plt
posts = []
exclude = set(string.punctuation)
with open('data.csv',"rt") as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
for row in spamreader:
row = ''.join(ch for ch in row if ch not in exclude)
row = ''.join(ch for ch in row if ch not in exclude)
row = ''.join(ch for ch in row if ch not in exclude)
posts.append(row)
with open('negativewords.txt', 'r') as f:
negatives = f.readlines()
for index, item in enumerate(negatives):
negatives[index] = item.rstrip()
scores = []
for post in posts:
scores.append(0)
for word in post.split(" "):
if word in negatives:
i = posts.index(post)
scores[i] = scores[i] + 1
LNF = []
with open('LNF.csv',"rt") as csvfile:
spamreader = csv.reader(csvfile, delimiter=',')
for row in spamreader:
for number in row:
LNF.append(int(number))
LNF_data = np.asarray(LNF)
scores_data = np.asarray(scores)
N = 272
colors = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radiuses
plt.scatter(scores_data, LNF_data, s=area, c=colors, alpha=0.5)
plt.title("Scatterplot Negative Scores vs. LNF")
plt.xlabel("Negative Scores")
plt.ylabel("LNF")
plt.show()