-
Notifications
You must be signed in to change notification settings - Fork 0
/
eleceval.py
92 lines (72 loc) · 2.46 KB
/
eleceval.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from sklearn.metrics import mean_squared_error,mean_absolute_error
import numpy as np
from keras.metrics import mean_absolute_percentage_error
from sklearn.metrics import r2_score
import math
# ¼ÆËãRMSE
def calcRMSE(pred,true):
return np.sqrt(mean_squared_error(true,pred))
def calcMSE(pred,true):
return mean_squared_error(true,pred)
# ¼ÆËãMAE
def calcMAE(pred,true):
#pred = pred[:, 0]
return mean_absolute_error(true,pred)
# ¼ÆËãMAPE
def calcMAPE(pred,true, epsion = 0.0000000):
#pred = pred[:,0] # ÁÐתÐУ¬±ãÓڹ㲥¼ÆËãÎó²îÖ¸±ê
# print (true-pred).shape
# print true.shape
# print pred.shape
#true += epsion
return np.sum(np.abs((true-pred)/(true+0.001)))*100/len(true)
#return mean_absolute_percentage_error(true, pred) 返回平均百分比误差
# ¼ÆËãSMAPE
def calcSMAPE(pred,true):
delim = (np.abs(true)+np.abs(pred))/2.0
return np.sum(np.abs((true-pred)/delim))/len(true)*100
def calcMaape(pred, true):
x = 0
for i in range(len(true)):
x += math.atan(np.abs((true[i] - pred[i])/pred[i]))
return x/len(true)
def mape(predicted, test):
temps = 0.0
instances = 0
for i in range(len(predicted)):
temps += abs(predicted[i]-test[i])*100.0/test[i]
instances += 1
return temps/instances
def mpe(predicted, test):
if not len(predicted) == len(test):
print("Predicted values and output test instances do not match.")
temps = 0.0
instances = 0
for i in range(len(predicted)):
temps += (predicted[i]-test[i])*100.0/test[i]
instances += 1
return temps/instances
def mse(predicted, test):
if not len(predicted) == len(test):
print("Predicted values and output test instances do not match.")
temps = 0.0
instances = 0
for i in range(len(predicted)):
temps += (predicted[i]-test[i])**2
instances += 1
return temps/instances
def rmse(predicted, test):
return (mse(predicted, test))**0.5
def mae(predicted, test):
if not len(predicted) != len(test):
print("Predicted values and output test instances do not match.")
temps = 0.0
instances = 0
for i in range(len(predicted)):
temps += abs(predicted[i]-test[i])
instances += 1
return temps/instances
def r2(predicted, test):
if not len(predicted) == len(test):
print("Predicted values and output test instances do not match.")
return r2_score(test, predicted)