-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearner.py
executable file
·23 lines (19 loc) · 1.02 KB
/
learner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import data
class Learner():
def __init__(self):
pass
def updateProbs(self, words ,is_flu):
if is_flu:
for word in data.probabilities:
fluTweetsWithWord = data.probabilities[word][0] * (data.numFluTweets - 1)
if not word in words:
data.probabilities[word] = ((fluTweetsWithWord / data.numFluTweets), data.probabilities[word][1])
else:
data.probabilities[word] = (((fluTweetsWithWord+1) / data.numFluTweets), data.probabilities[word][1])
else:
for word in data.probabilities:
healthyTweetsWithWord = data.probabilities[word][1] * (data.numHealthyTweets - 1)
if not word in words:
data.probabilities[word] = (data.probabilities[word][0], (healthyTweetsWithWord / data.numHealthyTweets))
else:
data.probabilities[word] = (data.probabilities[word][0], ((healthyTweetsWithWord+1)/ data.numHealthyTweets))