mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-09-16 22:20:23 +00:00
Add RMSE as cross validation metric
This commit is contained in:
parent
9a5752f019
commit
7179ae3a38
2 changed files with 10 additions and 3 deletions
|
|
@ -202,6 +202,7 @@ def performance_metrics(df, metrics=None, rolling_window=0.05):
|
||||||
Computes a suite of performance metrics on the output of cross-validation.
|
Computes a suite of performance metrics on the output of cross-validation.
|
||||||
By default the following metrics are included:
|
By default the following metrics are included:
|
||||||
'mse': mean squared error
|
'mse': mean squared error
|
||||||
|
'rmse': root mean squared error
|
||||||
'mae': mean absolute error
|
'mae': mean absolute error
|
||||||
'mape': mean percent error
|
'mape': mean percent error
|
||||||
'coverage': coverage of the upper and lower intervals
|
'coverage': coverage of the upper and lower intervals
|
||||||
|
|
@ -226,7 +227,7 @@ def performance_metrics(df, metrics=None, rolling_window=0.05):
|
||||||
----------
|
----------
|
||||||
df: The dataframe returned by cross_validation.
|
df: The dataframe returned by cross_validation.
|
||||||
metrics: A list of performance metrics to compute. If not provided, will
|
metrics: A list of performance metrics to compute. If not provided, will
|
||||||
use ['mse', 'mae', 'mape', 'coverage'].
|
use ['mse', 'mae', 'mape', 'coverage', 'rmse'].
|
||||||
rolling_window: Proportion of data to use in each rolling window for
|
rolling_window: Proportion of data to use in each rolling window for
|
||||||
computing the metrics.
|
computing the metrics.
|
||||||
|
|
||||||
|
|
@ -234,7 +235,7 @@ def performance_metrics(df, metrics=None, rolling_window=0.05):
|
||||||
-------
|
-------
|
||||||
Dataframe with a column for each metric, and column 'horizon'
|
Dataframe with a column for each metric, and column 'horizon'
|
||||||
"""
|
"""
|
||||||
valid_metrics = ['mse', 'mae', 'mape', 'coverage']
|
valid_metrics = ['mse', 'rmse', 'mae', 'mape', 'coverage']
|
||||||
if metrics is None:
|
if metrics is None:
|
||||||
metrics = valid_metrics
|
metrics = valid_metrics
|
||||||
if len(set(metrics)) != len(metrics):
|
if len(set(metrics)) != len(metrics):
|
||||||
|
|
@ -277,6 +278,12 @@ def mse(df, w):
|
||||||
return rolling_mean(se.values, w)
|
return rolling_mean(se.values, w)
|
||||||
|
|
||||||
|
|
||||||
|
def rmse(df, w):
|
||||||
|
"""Root mean squared error
|
||||||
|
"""
|
||||||
|
return np.sqrt(mse(df, w))
|
||||||
|
|
||||||
|
|
||||||
def mae(df, w):
|
def mae(df, w):
|
||||||
"""Mean absolute error
|
"""Mean absolute error
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ class TestDiagnostics(TestCase):
|
||||||
df_none = diagnostics.performance_metrics(df_cv, rolling_window=0)
|
df_none = diagnostics.performance_metrics(df_cv, rolling_window=0)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
set(df_none.columns),
|
set(df_none.columns),
|
||||||
{'horizon', 'coverage', 'mae', 'mape', 'mse'},
|
{'horizon', 'coverage', 'mae', 'mape', 'mse', 'rmse'},
|
||||||
)
|
)
|
||||||
self.assertEqual(df_none.shape[0], 14)
|
self.assertEqual(df_none.shape[0], 14)
|
||||||
# Aggregation level 0.2
|
# Aggregation level 0.2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue