diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-02-23 10:23:00 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-02-23 10:23:00 +0100 |
commit | 25b4281ef57486b925fd86f2ce9d8a0fff608d29 (patch) | |
tree | 7c51cebb4fdccb0a244510a3a1d6e6bd23a331ef | |
parent | a5f79cd57a709bce08f365416e9aebd2fb9b481e (diff) |
regression_measures: add R^2 coefficient of determination score function
-rwxr-xr-x | lib/dfatool.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/dfatool.py b/lib/dfatool.py index 4a4435d..40cacef 100755 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -7,7 +7,8 @@ import json import numpy as np import os from scipy import optimize -from scipy.cluster.vq import kmeans2 +from gplearn.genetic import SymbolicRegressor +from sklearn.metrics import r2_score import struct import sys import tarfile @@ -74,6 +75,7 @@ def regression_measures(predicted, actual): if type(actual) != np.ndarray: raise ValueError('second arg must be ndarray, is {}'.format(type(actual))) deviations = predicted - actual + mean = np.mean(actual) if len(deviations) == 0: return {} measures = { @@ -81,12 +83,17 @@ def regression_measures(predicted, actual): 'msd' : np.mean(deviations**2, dtype=np.float64), 'rmsd' : np.sqrt(np.mean(deviations**2), dtype=np.float64), 'ssr' : np.sum(deviations**2, dtype=np.float64), + 'rsq' : r2_score(actual, predicted), } + #rsq_quotient = np.sum((actual - mean)**2, dtype=np.float64) * np.sum((predicted - mean)**2, dtype=np.float64) + if np.all(actual != 0): measures['mape'] = np.mean(np.abs(deviations / actual)) * 100 # bad measure if np.all(np.abs(predicted) + np.abs(actual) != 0): measures['smape'] = np.mean(np.abs(deviations) / (( np.abs(predicted) + np.abs(actual)) / 2 )) * 100 + #if np.all(rsq_quotient != 0): + # measures['rsq'] = (np.sum((actual - mean) * (predicted - mean), dtype=np.float64)**2) / rsq_quotient return measures |