2022-05-10 23:56:56 +02:00
|
|
|
import pandas as pd
|
|
|
|
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
|
|
from sklearn.naive_bayes import MultinomialNB
|
|
|
|
from sklearn.pipeline import make_pipeline
|
|
|
|
from sklearn.metrics import accuracy_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
df = pd.read_csv("train/train.tsv", sep="\t", header=None, error_bad_lines=False)
|
2022-05-11 00:59:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-10 23:56:56 +02:00
|
|
|
dev_x = pd.read_csv("dev-0/in.tsv", sep="\t", header=None, error_bad_lines=False)
|
2022-05-11 00:59:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
with open('test-A/in.tsv', 'r', encoding='utf8') as file:
|
|
|
|
test = file.readlines()
|
|
|
|
test = pd.Series(test)
|
|
|
|
|
2022-05-10 23:56:56 +02:00
|
|
|
|
|
|
|
x = df[1]
|
|
|
|
y = df[0]
|
|
|
|
|
|
|
|
model = make_pipeline(TfidfVectorizer(), MultinomialNB())
|
|
|
|
model.fit(x,y)
|
|
|
|
|
|
|
|
pred_dev = model.predict(dev_x[0])
|
2022-05-11 00:59:27 +02:00
|
|
|
pred_dev = pd.Series(pred_dev)
|
2022-05-10 23:56:56 +02:00
|
|
|
|
2022-05-11 00:59:27 +02:00
|
|
|
with open('dev-0/out.tsv', 'wt') as file:
|
2022-05-10 23:56:56 +02:00
|
|
|
for pred in pred_dev:
|
2022-05-11 00:59:27 +02:00
|
|
|
file.write(str(pred)+'\n')
|
|
|
|
|
|
|
|
|
|
|
|
pred_test = model.predict(test)
|
|
|
|
pred_test = pd.Series(pred_test)
|
|
|
|
pred_test = pred_test.astype('int')
|
2022-05-10 23:56:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-11 00:59:27 +02:00
|
|
|
with open('test-A/out.tsv', 'wt') as file:
|
|
|
|
for pred in pred_test:
|
|
|
|
file.write(str(pred)+'\n')
|
|
|
|
|