56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
import pickle
|
|
import sys
|
|
import torch
|
|
import pandas as pd
|
|
|
|
def read_data_file(filepath):
|
|
df = pd.read_csv(filepath, sep='\t', header=None, index_col=None)
|
|
dataframe = df.iloc[:, [7,10]]
|
|
dataframe.columns = ['biggy','type']
|
|
#print(dataframe.size[0])
|
|
# for x in range(len(dataframe)):
|
|
# dataframe['biggy'].loc[x] = dataframe['biggy'].loc[x].replace(" ","")
|
|
#such dumb solution, well, but at least it works
|
|
dataframe['bias'] = 1
|
|
dataframe['biggy'] = dataframe['biggy'].astype(float)
|
|
return dataframe
|
|
|
|
def dataframe_to_arrays(dataframe):
|
|
dataframe1 = dataframe.copy(deep=True)
|
|
#dataframe1["type"] = dataframe1["type"].astype('category').cat.codes
|
|
|
|
|
|
dataframe1 = pd.get_dummies(dataframe1, columns=['type'])
|
|
if 'type_apartamentowiec' not in dataframe1:
|
|
dataframe1['type_apartamentowiec'] = 0
|
|
if 'type_blok' not in dataframe1:
|
|
dataframe1['type_blok'] = 0
|
|
if 'type_dom wolnostojący' not in dataframe1:
|
|
dataframe1['type_dom wolnostojący'] = 0
|
|
if 'type_loft' not in dataframe1:
|
|
dataframe1['type_loft'] = 0
|
|
if 'type_kamienica' not in dataframe1:
|
|
dataframe1['type_kamienica'] = 0
|
|
if 'type_plomba' not in dataframe1:
|
|
dataframe1['type_plomba'] = 0
|
|
if 'type_szeregowiec' not in dataframe1:
|
|
dataframe1['type_szeregowiec'] = 0
|
|
|
|
return dataframe1
|
|
|
|
#PREDICT_FILE_PATH = 'dev-0/in.tsv'
|
|
PREDICT_FILE_PATH = 'test-A/in.tsv'
|
|
|
|
def main():
|
|
w = pickle.load(open('model.pkl', 'rb'))
|
|
|
|
data = read_data_file(PREDICT_FILE_PATH)
|
|
data = dataframe_to_arrays(data)
|
|
|
|
for index, row in data.iterrows():
|
|
#print(row[0], row[1])
|
|
x = torch.tensor([float(row[0]), float(row[1]), 1, float(row[3]), float(row[4]),float(row[5]),float(row[6]),float(row[7]),float(row[8])])
|
|
y = x @ w
|
|
print(y.item())
|
|
|
|
main() |