-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_model.py
56 lines (36 loc) · 1.12 KB
/
test_model.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
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 2 22:16:06 2018
@author: Trushant Kalyanpur
"""
import numpy as np
import matplotlib.pyplot as plt
import pickle
from regression_model import regression_model
from sklearn.metrics import mean_squared_error,r2_score,mean_absolute_error
import pandas as pd
#import xgboost as xgb
import ml_functions as dp
#Import test data
test_df = pd.read_csv('new_test.csv')
#Initialize and load pre-trained model
regressor = regression_model()
model_path = 'random_forest_ww46'
regressor.loadModel(model_path)
#Impute missing values with mean
#X_imputed = dp.impute_missing_mean(test_df)
#X = X_imputed
#Drop sale price since this is the target value
X_test = test_df.drop("SalePrice",axis=1)
#Target feature
y_true = test_df["SalePrice"]
#Predicted values
#uncomment for non-xgboost models
#y_pred = regressor.predict(X_test)
#Uncomment for xgboost
y_pred = regressor.predict(X_test.values)
#Calculate Mean Absolute Error and R2 score based on predictions
mae = mean_absolute_error(y_true,y_pred)
r2 = r2_score(y_true,y_pred)
print ("Mean absolute error=",mae)
print ("R2 score=",r2)