auta-public/solution.py

153 lines
1.9 KiB
Python
Raw Normal View History

2021-05-06 11:28:34 +02:00
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
from pathlib import Path
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
# ## TRENING
# In[2]:
NAMES = ["Price","Mileage","Year","Brand","EngineType","EngineCapacity"]
TRAIN_BASE = pd.read_csv("train/train.tsv", sep ='\t', names=NAMES)
# In[3]:
Y_TRAIN = np.array(TRAIN_BASE["Price"])
X_TRAIN = np.array(TRAIN_BASE[["Mileage","Year","EngineCapacity"]])
# In[4]:
MODEL = LinearRegression().fit(X_TRAIN,Y_TRAIN)
# ## DEV-0
# In[5]:
NAMES = ["Mileage","Year","Brand","EngineType","EngineCapacity"]
FILE_BASE = pd.read_csv("dev-0/in.tsv", sep ='\t', names=NAMES)
# In[6]:
X_TEST = np.array(FILE_BASE[["Mileage","Year","EngineCapacity"]])
# In[7]:
Y_TEST = MODEL.predict(X_TEST)
# In[8]:
VALUES = np.array2string(Y_TEST, precision=5, separator='\n',suppress_small=True)
# In[9]:
VALUES = VALUES.split(".\n")
# In[10]:
OUTFILE = open("dev-0/out.tsv", "w")
# In[11]:
for x in VALUES:
RESULT = x.replace(" ","")
RESULT = RESULT.replace("[","")
RESULT = RESULT.replace("]","")
OUTFILE.write(str(RESULT))
# In[12]:
OUTFILE.close()
# ## TEST A
# In[13]:
NAMES = ["Mileage","Year","Brand","EngineType","EngineCapacity"]
FILE_BASE = pd.read_csv("test-A/in.tsv", sep ='\t', names=NAMES)
# In[14]:
X_TEST = np.array(FILE_BASE[["Mileage","Year","EngineCapacity"]])
# In[15]:
Y_TEST = MODEL.predict(X_TEST)
# In[16]:
VALUES = np.array2string(Y_TEST, precision=5, separator='\n',suppress_small=True)
# In[17]:
VALUES = VALUES.split(".\n")
# In[18]:
OUTFILE = open("test-A/out.tsv", "w")
# In[19]:
for x in VALUES:
RESULT = x.replace(" ","")
RESULT = RESULT.replace("[","")
RESULT = RESULT.replace("]","")
OUTFILE.write(str(RESULT) )
# In[20]:
OUTFILE.close()
# In[ ]: