-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathaccuracy.py
57 lines (38 loc) · 1.17 KB
/
accuracy.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
"""
computing accuracy metrics, and the index as follow:
rmse
mse
mae
fcp
"""
import numpy as np
def rmse(predictions, verbose):
"""compute RMSE(Root Mean Squared Error)."""
if not predictions:
raise ValueError("Prediction list is empty.")
mse = np.mean([(true_r - est)**2
for (_, _, true_r, est, _) in predictions])
rmse_ = np.sqrt(mse)
if verbose:
print('RMSE: {0: 1.4f}'.format(rmse_))
return rmse_
def mse(predictions, verbose):
"""Compute MSE(Mean Squared Error)."""
if not predictions:
raise ValueError("Prediction list is empty.")
mse_ = np.mean([(true_r - est)**2
for (_, _, true_r, est, _) in predictions])
if verbose:
print('MSE: {0: 1.4f}'.format(mse_))
return mse_
def mae(predictions, verbose):
"""Compute MAE(Mean Absolute Error)."""
if not predictions:
raise ValueError("Prediction list is empty.")
mae_ = np.mean([abs(true_r - est)
for (_, _, true_r, est, _) in predictions])
if verbose:
print('MAE: {0: 1.4f}'.format(mae_))
return mae_
def fcp(predictions, verbose):
pass