2021-04-27 20:51:28 +02:00
|
|
|
import csv
|
|
|
|
|
2021-04-27 19:36:55 +02:00
|
|
|
import gensim as gensim
|
|
|
|
import smart_open
|
|
|
|
from sklearn.feature_extraction.text import TfidfVectorizer
|
|
|
|
from sklearn.linear_model import LinearRegression
|
|
|
|
from stop_words import get_stop_words
|
|
|
|
from sklearn.cluster import KMeans
|
|
|
|
from gensim.models.doc2vec import Doc2Vec
|
|
|
|
import os
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
def read_train_file(inDirectory):
|
|
|
|
colnames = ['start_date', 'end_date', 'title', 'sort_title', 'data']
|
|
|
|
df_train = pd.read_csv(inDirectory, sep="\t", names=colnames)
|
2021-04-27 20:51:28 +02:00
|
|
|
return df_train[:tain_set]
|
2021-04-27 19:36:55 +02:00
|
|
|
|
|
|
|
def read_evaluate_file(inDirectory):
|
|
|
|
colnames = ['data']
|
2021-04-27 20:51:28 +02:00
|
|
|
df_train = pd.read_csv(inDirectory, sep="\t", names=colnames, quoting=csv.QUOTE_NONE, error_bad_lines=False)
|
|
|
|
return df_train
|
2021-04-27 19:36:55 +02:00
|
|
|
|
|
|
|
def train_date_mean(df):
|
|
|
|
date_mean = (df['start_date'] + df['end_date']) / 2
|
|
|
|
return date_mean
|
|
|
|
|
2021-04-27 20:51:28 +02:00
|
|
|
tain_set = 50000
|
2021-04-27 19:36:55 +02:00
|
|
|
|
|
|
|
df = read_train_file('train/train.tsv')
|
2021-04-27 20:51:28 +02:00
|
|
|
date_mean_df = train_date_mean(df)
|
2021-04-27 19:36:55 +02:00
|
|
|
vectorizer = TfidfVectorizer(stop_words=get_stop_words('polish'))
|
|
|
|
train_vectorized_corpus = vectorizer.fit_transform(df['data'])
|
|
|
|
reg = LinearRegression().fit(train_vectorized_corpus, date_mean_df)
|
|
|
|
|
|
|
|
df_evaluate = read_evaluate_file('dev-0/in.tsv')
|
|
|
|
evaluate_vectorized_corpus = vectorizer.transform(df_evaluate['data'])
|
|
|
|
evaluate = reg.predict(evaluate_vectorized_corpus)
|
|
|
|
with open("dev-0/out.tsv", 'w') as file:
|
|
|
|
for e in evaluate:
|
2021-04-27 20:51:28 +02:00
|
|
|
file.write("%i\n" % e)
|
|
|
|
|
|
|
|
|
|
|
|
os.system("./geval -t dev-0")
|