s444476 add solution

This commit is contained in:
Maciej Ścigacz 2022-05-01 13:49:59 +02:00
parent 33b70ce7b1
commit 11b4c60bc0
6 changed files with 153308 additions and 0 deletions

20000
dev-0/out.tsv Normal file

File diff suppressed because it is too large Load Diff

11563
dev-1/out.tsv Normal file

File diff suppressed because it is too large Load Diff

38
run.py Normal file
View File

@ -0,0 +1,38 @@
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.feature_extraction.text import TfidfVectorizer
def linear_regression(train_path, predict_path, out_path):
print("Wczytywanie zbioru treningowego")
train = pd.read_csv(train_path, sep='\t', header=None)
X_train = train[4]
Y_train = train[0]
print("Wczytywanie pliku do predykcji")
pred_x = []
with open(predict_path, encoding='utf-8') as f:
for line in f:
pred_x.append(line)
print("Wektoryzacja")
vectorizer = TfidfVectorizer()
X_train = vectorizer.fit_transform(X_train)
pred_x = vectorizer.transform(pred_x)
print("Uczenie modelu")
model = LinearRegression()
model.fit(X_train, Y_train)
print("Predykcja wyników")
pred_y = model.predict(pred_x)
print("Zapis do pliku")
pd.DataFrame(pred_y).to_csv(out_path, header=False, index=None)
linear_regression("train/train.tsv", "dev-0/in.tsv", "dev-0/out.tsv")
linear_regression("train/train.tsv", "dev-1/in.tsv", "dev-1/out.tsv")
linear_regression("train/train.tsv", "test-A/in.tsv", "test-A/out.tsv")

14220
test-A/out.tsv Normal file

File diff suppressed because it is too large Load Diff

16
testing.py Normal file
View File

@ -0,0 +1,16 @@
from sklearn.metrics import mean_squared_error
import pandas as pd
def RMSE(exp, pred):
expected = exp
predicted = pred
data_exp = pd.read_csv(expected, header=0, sep='\t')
data_pred = pd.read_csv(predicted, header=0, sep='\t')
rmse = mean_squared_error(data_exp, data_pred, squared=False)
return rmse
print(RMSE("dev-0/expected.tsv", "dev-0/out.tsv"))
print(RMSE("dev-1/expected.tsv", "dev-1/out.tsv"))

107471
train/train.tsv Normal file

File diff suppressed because one or more lines are too long