forked from kubapok/auta-public
79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
|
|
from sklearn.linear_model import LinearRegression
|
|
import pandas as pd
|
|
import string
|
|
import csv
|
|
|
|
|
|
|
|
price = []
|
|
mileage = []
|
|
year = []
|
|
brand = []
|
|
enginetype = []
|
|
enginecapacity = []
|
|
with open("train/train.tsv") as tsv:
|
|
for line in csv.reader(tsv, delimiter="\t"):
|
|
price.append(line[0])
|
|
mileage.append(line[1])
|
|
year.append(line[2])
|
|
brand.append(line[3])
|
|
enginetype.append(line[4])
|
|
enginecapacity.append(line[5])
|
|
|
|
cena = pd.DataFrame(list(zip(price)))
|
|
reszta = pd.DataFrame(list(zip(mileage,year,enginecapacity)))
|
|
model = LinearRegression().fit(reszta,cena)
|
|
|
|
|
|
out1 = open("dev-0/out.tsv", "w")
|
|
mileage_dev = []
|
|
year_dev = []
|
|
brand_dev = []
|
|
enginetype_dev = []
|
|
enginecapacity_dev = []
|
|
with open("dev-0/in.tsv") as tsv:
|
|
for line in csv.reader(tsv, delimiter="\t"):
|
|
mileage_dev.append(line[0])
|
|
year_dev.append(line[1])
|
|
brand_dev.append(line[2])
|
|
enginetype_dev.append(line[3])
|
|
enginecapacity_dev.append(line[4])
|
|
|
|
do_predykcji1 = pd.DataFrame(list(zip(mileage_dev,year_dev,enginecapacity_dev)))
|
|
predict1 = model.predict(do_predykcji1)
|
|
|
|
for x in predict1:
|
|
new1 = str(x).replace('[','')
|
|
new1 = str(new1).replace(']','')
|
|
out1.write(str(new1) + '\n')
|
|
out1.close()
|
|
|
|
|
|
|
|
out2 = open("test-A/out.tsv", "w")
|
|
mileage_test = []
|
|
year_test = []
|
|
brand_test = []
|
|
enginetype_test = []
|
|
enginecapacity_test = []
|
|
with open("test-A/in.tsv") as tsv:
|
|
for line in csv.reader(tsv, delimiter="\t"):
|
|
mileage_test.append(line[0])
|
|
year_test.append(line[1])
|
|
brand_test.append(line[2])
|
|
enginetype_test.append(line[3])
|
|
enginecapacity_test.append(line[4])
|
|
|
|
do_predykcji2 = pd.DataFrame(list(zip(mileage_test,year_test,enginecapacity_test)))
|
|
predict2 = model.predict(do_predykcji2)
|
|
|
|
for y in predict2:
|
|
new2 = str(y).replace('[','')
|
|
new2 = str(new2).replace(']','')
|
|
out2.write(str(new2) + '\n')
|
|
out2.close()
|