linear reg
This commit is contained in:
parent
5c4bb10ddf
commit
0d3859e598
1000
dev-0/out.tsv
Normal file
1000
dev-0/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
39
linearRegression.py
Normal file
39
linearRegression.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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')
|
||||||
|
# --------------
|
1000
test-A/out.tsv
Normal file
1000
test-A/out.tsv
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user