From b94b71a4a4492e8bf4b5d96a244bbeaa5996833e Mon Sep 17 00:00:00 2001 From: s152483 Date: Fri, 10 Apr 2020 22:16:50 +0000 Subject: [PATCH] =?UTF-8?q?Usu=C5=84=20'predict=5Flr.py'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- predict_lr.py | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 predict_lr.py diff --git a/predict_lr.py b/predict_lr.py deleted file mode 100644 index 0dc0730..0000000 --- a/predict_lr.py +++ /dev/null @@ -1,36 +0,0 @@ -import pickle -import sys -import math -import fileinput - -model = pickle.load(open("model.pkl", "rb")) -word_index, vocabulary, weights, words_count = model - -def predict(): - output = [] - for line in fileinput.input(openhook=fileinput.hook_encoded("utf-8")): - line = line.rstrip() - fields = line.split('\t') - label = fields[0].strip() - document = fields[0] - terms = document.split(' ') - for term in terms: - if term in words_count: - words_count[term] += 1 - else: - words_count[term] = 1 - expected = weights[0] - for t in terms: - if t in vocabulary: - expected +=(words_count[t]/len(words_count)*(weights[word_index[t]])) - if expected > 0.9: - output.append(1) - else: - output.append(0) - - with open("out.tsv", "w") as out: - for val in output: - out.write(str(val)+"\n") - -predict() -