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
|
52
main.py
52
main.py
@ -4,38 +4,33 @@ from sklearn.linear_model import LinearRegression
|
|||||||
from sklearn.metrics import mean_squared_error
|
from sklearn.metrics import mean_squared_error
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
df = pd.read_csv("train/train.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',
|
||||||
dev0 = pd.read_csv("dev-0/in.tsv", header=None, sep="\t", error_bad_lines=False)
|
'brand', 'engineType',
|
||||||
testA = pd.read_csv("test-A/in.tsv", header=None, sep="\t", error_bad_lines=False)
|
'engineCapacity'])
|
||||||
expected = pd.read_csv("dev-0/expected.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, 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()
|
df = df[['price', 'year', 'mileage', 'engineCapacity']]
|
||||||
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)
|
|
||||||
|
|
||||||
test_testA = testA.copy()
|
min_val = np.min(df)
|
||||||
test_testA.insert(0, "dum", 0, True)
|
max_val = np.max(df)
|
||||||
test_testA = test_testA.rename(columns={"dum": 0, 0: 1, 1: 2, 2: 3, 3: 4, 4: 5, 5: 6})
|
df = (df - min_val) / (max_val - min_val)
|
||||||
all_df = all_df.append(test_testA, ignore_index=True)
|
|
||||||
all_df = pd.get_dummies(all_df, columns=[3, 4])
|
|
||||||
|
|
||||||
min_val = np.min(all_df)
|
Y = df[['price']]
|
||||||
max_val = np.max(all_df)
|
X = df[['year', 'mileage', 'engineCapacity']]
|
||||||
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]]
|
|
||||||
|
|
||||||
model = LinearRegression().fit(X, Y)
|
model = LinearRegression().fit(X, Y)
|
||||||
|
|
||||||
predicted_dev0 = model.predict(dummy_dev0[dummy_dev0.columns[1:]])
|
dev0 = (dev0[['year', 'mileage', 'engineCapacity']] - min_val) / (max_val - min_val)
|
||||||
predicted_testA = model.predict(dummy_testA[dummy_testA.columns[1:]])
|
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:
|
with open("dev-0/out.tsv", "w") as file:
|
||||||
for pred in predicted_dev0:
|
for pred in predicted_dev0:
|
||||||
@ -45,9 +40,11 @@ with open("test-A/out.tsv", "w") as file:
|
|||||||
for pred in predicted_testA:
|
for pred in predicted_testA:
|
||||||
file.write(str(pred[0]) + "\n")
|
file.write(str(pred[0]) + "\n")
|
||||||
|
|
||||||
|
|
||||||
predicted_denormalized = []
|
predicted_denormalized = []
|
||||||
for pred in predicted_dev0:
|
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'])
|
predicted_denormalized = DataFrame(predicted_denormalized, columns=['pred'])
|
||||||
error = mean_squared_error(expected, predicted_denormalized)
|
error = mean_squared_error(expected, predicted_denormalized)
|
||||||
@ -57,3 +54,4 @@ for exp, pred in zip(expected.values, predicted_denormalized.values):
|
|||||||
f = open("dev0_rmse.txt", "w")
|
f = open("dev0_rmse.txt", "w")
|
||||||
f.write(str(error))
|
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