forked from kubapok/auta-public
linear sklearn v2
This commit is contained in:
parent
4b141f3a8c
commit
916bb37c66
2000
dev-0/out.tsv
2000
dev-0/out.tsv
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
1013603084.8408571
|
||||
1165319253.2984157
|
56
main.py
56
main.py
@ -4,38 +4,33 @@ from sklearn.linear_model import LinearRegression
|
||||
from sklearn.metrics import mean_squared_error
|
||||
import numpy as np
|
||||
|
||||
df = pd.read_csv("train/train.tsv", header=None, sep="\t", error_bad_lines=False)
|
||||
dev0 = pd.read_csv("dev-0/in.tsv", header=None, sep="\t", error_bad_lines=False)
|
||||
testA = pd.read_csv("test-A/in.tsv", header=None, sep="\t", error_bad_lines=False)
|
||||
expected = pd.read_csv("dev-0/expected.tsv", header=None, sep="\t", error_bad_lines=False)
|
||||
df = pd.read_csv("train/train.tsv", header=None, sep="\t", error_bad_lines=False, names=['price', 'mileage', 'year',
|
||||
'brand', 'engineType',
|
||||
'engineCapacity'])
|
||||
dev0 = pd.read_csv("dev-0/in.tsv", header=None, sep="\t", error_bad_lines=False, names=['mileage', 'year',
|
||||
'brand', 'engineType',
|
||||
'engineCapacity'])
|
||||
testA = pd.read_csv("test-A/in.tsv", header=None, sep="\t", error_bad_lines=False, names=['mileage', 'year',
|
||||
'brand', 'engineType',
|
||||
'engineCapacity'])
|
||||
expected = pd.read_csv("dev-0/expected.tsv", header=None, sep="\t", error_bad_lines=False, names=['price'])
|
||||
|
||||
all_df = df.copy()
|
||||
test_dev0 = dev0.copy()
|
||||
test_dev0.insert(0, "dum", 0, True)
|
||||
test_dev0 = test_dev0.rename(columns={"dum": 0, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6})
|
||||
all_df = all_df.append(test_dev0, ignore_index=True)
|
||||
df = df[['price', 'year', 'mileage', 'engineCapacity']]
|
||||
|
||||
test_testA = testA.copy()
|
||||
test_testA.insert(0, "dum", 0, True)
|
||||
test_testA = test_testA.rename(columns={"dum": 0, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6})
|
||||
all_df = all_df.append(test_testA, ignore_index=True)
|
||||
all_df = pd.get_dummies(all_df, columns=[3, 4])
|
||||
min_val = np.min(df)
|
||||
max_val = np.max(df)
|
||||
df = (df - min_val) / (max_val - min_val)
|
||||
|
||||
min_val = np.min(all_df)
|
||||
max_val = np.max(all_df)
|
||||
all_df = (all_df - min_val) / (max_val - min_val)
|
||||
|
||||
dummy_df = all_df[:len(df)]
|
||||
dummy_dev0 = all_df[len(df):len(df) + len(dev0)]
|
||||
dummy_testA = all_df[len(df) + len(dev0):]
|
||||
|
||||
X = dummy_df[dummy_df.columns[1:]]
|
||||
Y = dummy_df[dummy_df.columns[:1]]
|
||||
Y = df[['price']]
|
||||
X = df[['year', 'mileage', 'engineCapacity']]
|
||||
|
||||
model = LinearRegression().fit(X, Y)
|
||||
|
||||
predicted_dev0 = model.predict(dummy_dev0[dummy_dev0.columns[1:]])
|
||||
predicted_testA = model.predict(dummy_testA[dummy_testA.columns[1:]])
|
||||
dev0 = (dev0[['year', 'mileage', 'engineCapacity']] - min_val) / (max_val - min_val)
|
||||
testA = (testA[['year', 'mileage', 'engineCapacity']] - min_val) / (max_val - min_val)
|
||||
|
||||
predicted_dev0 = model.predict(dev0[['year', 'mileage', 'engineCapacity']])
|
||||
predicted_testA = model.predict(testA[['year', 'mileage', 'engineCapacity']])
|
||||
|
||||
with open("dev-0/out.tsv", "w") as file:
|
||||
for pred in predicted_dev0:
|
||||
@ -45,15 +40,18 @@ with open("test-A/out.tsv", "w") as file:
|
||||
for pred in predicted_testA:
|
||||
file.write(str(pred[0]) + "\n")
|
||||
|
||||
|
||||
predicted_denormalized = []
|
||||
for pred in predicted_dev0:
|
||||
predicted_denormalized.append(pred[0] * (max_val[0] - min_val[0]) + min_val[0])
|
||||
denorm = pred[0] * (max_val[0] - min_val[0]) + min_val[0]
|
||||
predicted_denormalized.append(denorm)
|
||||
|
||||
predicted_denormalized = DataFrame(predicted_denormalized, columns=['pred'])
|
||||
error = mean_squared_error(expected, predicted_denormalized)
|
||||
for exp, pred in zip(expected.values, predicted_denormalized.values):
|
||||
print(exp, pred)
|
||||
|
||||
|
||||
f = open("dev0_rmse.txt", "w")
|
||||
f.write(str(error))
|
||||
f.close()
|
||||
f.close()
|
||||
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