-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_helper.py
56 lines (40 loc) · 1.22 KB
/
model_helper.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
55
56
import sqlite3
import pandas as pd
from sklearn import svm
from sklearn import linear_model
#@Author: Qin Zhi Guo
#@Version: 1.0
#SVM build Model
def predictBySVM(x_train,x_test,y_train):
clf = svm.SVR()
clf.fit(x_train, y_train.values.ravel())
y_predict = clf.predict(x_test)
return y_predict
#Linear Regression build Model
def predictByARDRegression(x_train,x_test,y_train):
model = linear_model.ARDRegression()
model.fit(x_train,y_train.values.ravel())
y_predict = model.predict(x_test)
return y_predict
#Linear Regression build Model
def predictByLR(x_train,x_test,y_train):
model = linear_model.LinearRegression()
model.fit(x_train,y_train.values.ravel())
y_predict = model.predict(x_test)
return y_predict
#Result gap caculation
def predictGAP(y_predict,y_actual):
y_actual = y_actual.astype(float).fillna(0.000)
y_gap = y_predict - y_actual.values.ravel()
return y_gap
# Prediction accuracy caculation Function for the test dataset
def result_accuracy(result,var):
count = 0
len = 0
for num in result:
len = len + 1
if abs(num) <= var:
count = count +1
count=round(count,3)
len=round(len,3)
return (count/len)