retroc2/run.py
2022-05-17 22:49:20 +02:00

49 lines
1.3 KiB
Python

from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import LinearRegression
with open('train/train.tsv', 'r', encoding='utf8') as f:
train = f.readlines()
with open('train/meta.tsv', 'r', encoding='utf8') as f:
expected = f.readlines()
for i in range(0, len(expected)):
expected[i] = expected[i].split('\t')[5]
vectorizer = TfidfVectorizer()
train = vectorizer.fit_transform(train)
model = LinearRegression()
model.fit(train, expected)
with open('dev-0/in.tsv', 'r', encoding='utf8') as f:
dev_0 = f.readlines()
dev_0 = vectorizer.transform(dev_0)
predicted_dev_0 = model.predict(dev_0)
with open('dev-0/out.tsv', 'wt') as f:
for p in predicted_dev_0:
f.write(str(p) + '\n')
f.close()
with open('dev-1/in.tsv', 'r', encoding='utf8') as f:
dev_1 = f.readlines()
dev_1 = vectorizer.transform(dev_1)
predicted_dev_1 = model.predict(dev_1)
with open('dev-1/out.tsv', 'wt') as f:
for p in predicted_dev_1:
f.write(str(p) + '\n')
f.close()
with open('test-A/in.tsv', 'r', encoding='utf8') as f:
test_A = f.readlines()
test_A = vectorizer.transform(test_A)
predicted_test_A = model.predict(test_A)
with open('test-A/out.tsv', 'wt') as f:
for p in predicted_test_A:
f.write(str(p) + '\n')
f.close()