retroc2/main.py

34 lines
1.1 KiB
Python
Raw Normal View History

2021-05-12 21:22:41 +02:00
import csv
2021-05-12 21:00:14 +02:00
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline
from sklearn.feature_extraction.text import TfidfVectorizer
col_names = ['start_date', 'end_date', 'title', 'source', 'content']
train_set = pd.read_table('train/train.tsv.xz', error_bad_lines=False, header=None, names=col_names)
2021-05-12 21:22:41 +02:00
dev_set = pd.read_table('dev-0/in.tsv', error_bad_lines=False, header=None, names=col_names[4:], quoting=csv.QUOTE_NONE,)
test_set = pd.read_table('test-A/in.tsv', error_bad_lines=False, header=None, names=col_names[4:], quoting=csv.QUOTE_NONE,)
2021-05-12 21:00:14 +02:00
train_set = train_set.head(10000)
X_train = train_set['content']
y_train = (train_set['start_date'] + train_set['end_date']) / 2
X_dev = dev_set['content']
X_test = test_set['content']
2021-05-12 21:22:41 +02:00
print(dev_set)
print(test_set)
2021-05-12 21:00:14 +02:00
print('Trenowanie modelu...')
model = make_pipeline(TfidfVectorizer(), LinearRegression())
model.fit(X_train, y_train)
print('Predykcje...')
dev_prediction = model.predict(X_dev)
test_prediction = model.predict(X_test)
dev_prediction.tofile('./dev-0/out.tsv', sep='\n')
test_prediction.tofile('./test-A/out.tsv', sep='\n')