paranormal-or-skeptic/predict.py

25 lines
588 B
Python
Raw Normal View History

2020-04-02 15:45:53 +02:00
#!/usr/bin/python3
import sys
import pickle
2020-04-06 13:07:14 +02:00
from math import log, exp
2020-04-02 15:45:53 +02:00
from tokenizer import tokenize
#Load model
model = pickle.load(open("model.pkl","rb"))
weights, word_to_index_mapping, word_count = model
for line in sys.stdin:
document = line.rstrip()
fields = document.split('\t')
document = fields[0]
terms = tokenize(document)
y_predicted = weights[0]
for word in terms:
y_predicted += weights[word_to_index_mapping.get(word,0)] * (word_count.get(word,0) / len(word_count))
2020-04-06 13:07:14 +02:00
if y_predicted <= 0.5:
2020-04-02 15:45:53 +02:00
print(0)
else:
2020-04-06 13:07:14 +02:00
print(1)