Advertisement
Th3NiKo

Predict linear

Apr 6th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import sys
  4. import pickle
  5. from math import log, exp
  6. from tokenizer import tokenize
  7.  
  8. #Load model
  9. model = pickle.load(open("model.pkl","rb"))
  10. weights, word_to_index_mapping, word_count = model
  11.  
  12. for line in sys.stdin:
  13.     document = line.rstrip()
  14.     fields = document.split('\t')
  15.     document = fields[0]
  16.     terms = tokenize(document)
  17.  
  18.     y_predicted = weights[0]
  19.     for word in terms:
  20.         y_predicted += weights[word_to_index_mapping.get(word,0)] * (word_count.get(word,0) / len(word_count))
  21.  
  22.     if y_predicted <= 0.5:
  23.         print(0)
  24.     else:
  25.         print(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement