-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.py
62 lines (43 loc) · 1.62 KB
/
test.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
import pickle
import matplotlib.pyplot as plt
def predict(query):
loaded_model = pickle.load(open("MultinomialNBModel2", 'rb'))
countVectorizer = pickle.load(open("MultinomialNBCountVectorizer2", "rb"))
vectorizedQuery = countVectorizer.transform([query]).toarray()
prediction = loaded_model.predict(vectorizedQuery)
probabilities = loaded_model.predict_proba([vectorizedQuery[0]])[0]
probabilities = [float(x) * 100 for x in probabilities]
return prediction, probabilities
def generateGraphs(numbersList, name, xlabel, ylabel, title):
fig = plt.figure()
movingAverages = getMovingAverage(numbersList)
plt.ylabel(ylabel)
plt.title(title)
plt.xlabel(xlabel)
# plt.yticks(range(0, 100), range(0, 100))
# plt.xticks(range(0, len(numbersList)))
# plt.ylim((0, 100))
# plt.xlim((0, len(numbersList)))
plt.axis([0, len(numbersList), 0, 100])
ax = plt.axes()
# ax.xaxis.set_ticks(range(len(numbersList)))
# ax.xaxis.set_ticklabels(range(len(numbersList)))
# plt.xticks(rotation=90)
ax.set_xticks([])
ax.yaxis.set_ticks(range(100, 10))
ax.yaxis.set_ticks(range(100, 10))
# ax.figure.autofmt_xdate()
plt.plot(numbersList)
plt.plot(movingAverages)
print(numbersList)
print(movingAverages)
plt.savefig(name, format='svg')
def getMovingAverage(numbersList):
averageList = []
alpha = 0.9
movingAverage = numbersList[0]
averageList.append(movingAverage)
for number in numbersList[1:]:
movingAverage = alpha * movingAverage + (1-alpha) * number
averageList.append(movingAverage)
return averageList