paranormal-or-skeptic-ISI-p.../program.py

25 lines
850 B
Python
Raw Normal View History

2021-04-20 18:55:51 +02:00
import numpy as np
from sklearn import preprocessing
2021-04-20 22:51:32 +02:00
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import make_pipeline
2021-04-20 18:55:51 +02:00
from sklearn.feature_extraction.text import TfidfVectorizer
2021-04-20 22:51:32 +02:00
2021-04-20 18:55:51 +02:00
le=preprocessing.LabelEncoder()
2021-04-20 22:51:32 +02:00
2021-04-20 18:55:51 +02:00
with open("train/in.tsv") as f:
2021-04-20 22:51:32 +02:00
X = f.readlines()
2021-04-20 18:55:51 +02:00
with open("train/expected.tsv") as ff:
Y = ff.readlines()
2021-04-20 22:51:32 +02:00
Y= le.fit_transform(Y)
with open("test-A/in.tsv") as d:
r = d.readlines()
gnb = make_pipeline(TfidfVectorizer(),MultinomialNB())
2021-04-20 18:55:51 +02:00
model=gnb.fit(X, Y)
2021-04-20 22:51:32 +02:00
y_pred=model.predict(r)
2021-04-20 18:55:51 +02:00
y_pred=np.array(y_pred)
2021-04-20 22:51:32 +02:00
np.set_printoptions(threshold=np.inf)
t=np.array2string(y_pred.flatten(), precision=2, separator='\n',suppress_small=True)
f = open("test-A/out.tsv", "a")
2021-04-20 18:55:51 +02:00
f.write(t)