forked from kubapok/auta-public
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import gzip
|
|
import pandas as pd
|
|
import numpy as np
|
|
from sklearn.linear_model import LinearRegression
|
|
from sklearn.utils import shuffle
|
|
from sklearn.metrics import accuracy_score
|
|
|
|
|
|
def preprocess(x):
|
|
x = pd.concat([x, x['engineType'].str.get_dummies().astype(bool)], axis = 1 )
|
|
x = x.drop(['engineType','brand'], axis = 1)
|
|
return x
|
|
|
|
baseUrl = '/home/przemek/ekstrakcja/auta-public/'
|
|
|
|
data = pd.read_table(baseUrl + 'train/train.tsv', error_bad_lines=False, header= None, names=['price', 'mileage', 'year','brand','engineType', 'engineCap'])
|
|
|
|
y_train = data['price']
|
|
x_train = data.iloc[:,1:]
|
|
x_train = preprocess(x_train)
|
|
|
|
model = LinearRegression()
|
|
model.fit(x_train, y_train)
|
|
|
|
# dev-0
|
|
x_dev = pd.read_table(baseUrl + 'dev-0/in.tsv', error_bad_lines=False, header= None, names=['mileage', 'year','brand','engineType', 'engineCap'])
|
|
x_dev = preprocess(x_dev)
|
|
|
|
y_pred = model.predict(x_dev)
|
|
y_pred.tofile(baseUrl + 'dev-0/out.tsv', sep='\n')
|
|
# --------------
|
|
|
|
# test-A
|
|
x_testA = pd.read_table(baseUrl + '/test-A/in.tsv', error_bad_lines=False, header= None, names=['mileage', 'year','brand','engineType', 'engineCap'])
|
|
x_testA = preprocess(x_testA)
|
|
|
|
y_predA = model.predict(x_testA)
|
|
y_predA.tofile(baseUrl + 'test-A/out.tsv', sep='\n')
|
|
# -------------- |