forked from kubapok/auta-public
change place of main.py
This commit is contained in:
parent
8293ebe7be
commit
11ce81b395
2000
dev-0/out.tsv
2000
dev-0/out.tsv
File diff suppressed because it is too large
Load Diff
50
main.py
Normal file
50
main.py
Normal file
@ -0,0 +1,50 @@
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.metrics import mean_squared_error
|
||||
|
||||
|
||||
with open('names') as f_names:
|
||||
names = f_names.read().rstrip('\n').split('\t')
|
||||
|
||||
|
||||
cars_train = pd.read_csv('train/train.tsv', sep='\t', names=names)
|
||||
|
||||
cars_train = pd.get_dummies(cars_train, columns=['engineType'])
|
||||
|
||||
|
||||
y_train = pd.DataFrame(cars_train['price'])
|
||||
cars_train.drop('price', inplace=True, axis=1)
|
||||
cars_train.drop('brand', inplace=True, axis=1)
|
||||
x_train = pd.DataFrame(cars_train)
|
||||
|
||||
model = LinearRegression()
|
||||
model.fit(x_train, y_train)
|
||||
|
||||
names.remove('price')
|
||||
|
||||
cars_dev = pd.read_csv('dev-0/in.tsv', sep='\t', names=names)
|
||||
with open('dev-0/expected.tsv', 'r') as dev_exp_f:
|
||||
Y_dev = np.array([float(x.rstrip('\n')) for x in dev_exp_f.readlines()])
|
||||
|
||||
cars_dev = pd.get_dummies(cars_dev, columns=['engineType'])
|
||||
cars_dev.drop('brand', inplace=True, axis=1)
|
||||
X_dev = pd.DataFrame(cars_dev)
|
||||
|
||||
Y_dev_predicted = model.predict(X_dev)
|
||||
pd.DataFrame(Y_dev_predicted).to_csv('dev-0/out.tsv', sep='\t', index=False)
|
||||
|
||||
|
||||
cars_test=pd.read_csv('test-A/in.tsv', sep='\t', names=names)
|
||||
cars_test = pd.get_dummies(cars_test, columns=['engineType'])
|
||||
cars_test.drop('brand', inplace=True, axis=1)
|
||||
X_test = pd.DataFrame(cars_test)
|
||||
|
||||
Y_test_predicted = model.predict(X_test)
|
||||
pd.DataFrame(Y_test_predicted).to_csv('test-A/out.tsv', sep='\t', index=False)
|
||||
|
||||
error = np.sqrt(mean_squared_error(Y_dev, Y_dev_predicted))
|
||||
print(error)
|
2000
test-A/out.tsv
2000
test-A/out.tsv
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user