-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
48 lines (35 loc) · 1.3 KB
/
predict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import argparse
import pandas as pd
from model import my_custom_accuracy
from preprocessing import parse_data
from joblib import load
from config import model_name, result_path
import warnings
import numpy as np
warnings.filterwarnings("ignore")
# Parsing script arguments
parser = argparse.ArgumentParser(description='Process input')
parser.add_argument('tsv_path', type=str, help='tsv file path')
args = parser.parse_args()
# Reading input TSV
data = pd.read_csv(args.tsv_path, sep="\t", index_col='id', parse_dates=['release_date'])
# Parse Data
parsed_data, parsed_label, parsed_index, parsed_log_label = parse_data(data, train=False)
# Load model
model = load(model_name)
# Predict on test
results = model.predict(parsed_data)
# results = np.expm1(results)
#results[results<0] = 0.0
# print(f"Loss on data {-my_custom_accuracy(parsed_log_label, results)}")
# Save to dataframe
prediction_df = pd.DataFrame(columns=['id', 'revenue'])
prediction_df['id'] = parsed_index
results = np.expm1(results)
prediction_df['revenue'] = results
# export prediction results
prediction_df.to_csv(result_path, index=False, header=False)
# check the loading file
# prediction_df = pd.read_csv(result_path,header=None)
# results = np.log1p(prediction_df[1])
# print(f"Loss on data {-my_custom_accuracy(parsed_log_label, results)}")