You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `performance_metrics` utility can be used to compute some useful statistics of the prediction performance (`yhat`, `yhat_lower`, and `yhat_upper` compared to `y`), as a function of the distance from the cutoff (how far into the future the prediction was). The statistics computed are mean squared error (MSE), root mean squared error (RMSE), mean absolute error (MAE), mean absolute percent error (MAPE), median absolute percent error (MDAPE) and coverage of the `yhat_lower` and `yhat_upper` estimates. These are computed on a rolling window of the predictions in `df_cv` after sorting by horizon (`ds` minus `cutoff`). By default 10% of the predictions will be included in each window, but this can be changed with the `rolling_window` argument.
155
155
156
156
157
+
158
+
In Python, you can also create custom performance metric using the `register_performance_metric` decorator. Created metric should contain following arguments:
159
+
160
+
- df: Cross-validation results dataframe.
161
+
162
+
- w: Aggregation window size.
163
+
164
+
165
+
166
+
and return:
167
+
168
+
- Dataframe with columns horizon and metric.
169
+
170
+
157
171
```R
158
172
# R
159
173
df.p<- performance_metrics(df.cv)
@@ -200,57 +214,143 @@ df_p.head()
200
214
<tr>
201
215
<th>0</th>
202
216
<td>37 days</td>
203
-
<td>0.493764</td>
204
-
<td>0.702683</td>
205
-
<td>0.504754</td>
206
-
<td>0.058485</td>
207
-
<td>0.049922</td>
208
-
<td>0.058774</td>
209
-
<td>0.674052</td>
217
+
<td>0.493358</td>
218
+
<td>0.702395</td>
219
+
<td>0.503977</td>
220
+
<td>0.058376</td>
221
+
<td>0.049365</td>
222
+
<td>0.058677</td>
223
+
<td>0.676565</td>
210
224
</tr>
211
225
<tr>
212
226
<th>1</th>
213
227
<td>38 days</td>
214
-
<td>0.499522</td>
215
-
<td>0.706769</td>
216
-
<td>0.509723</td>
217
-
<td>0.059060</td>
218
-
<td>0.049389</td>
219
-
<td>0.059409</td>
220
-
<td>0.672910</td>
228
+
<td>0.499112</td>
229
+
<td>0.706478</td>
230
+
<td>0.508946</td>
231
+
<td>0.058951</td>
232
+
<td>0.049135</td>
233
+
<td>0.059312</td>
234
+
<td>0.675423</td>
221
235
</tr>
222
236
<tr>
223
237
<th>2</th>
224
238
<td>39 days</td>
225
-
<td>0.521614</td>
226
-
<td>0.722229</td>
227
-
<td>0.515793</td>
228
-
<td>0.059657</td>
229
-
<td>0.049540</td>
230
-
<td>0.060131</td>
231
-
<td>0.670169</td>
239
+
<td>0.521344</td>
240
+
<td>0.722042</td>
241
+
<td>0.515016</td>
242
+
<td>0.059547</td>
243
+
<td>0.049225</td>
244
+
<td>0.060034</td>
245
+
<td>0.672682</td>
232
246
</tr>
233
247
<tr>
234
248
<th>3</th>
235
249
<td>40 days</td>
236
-
<td>0.528760</td>
237
-
<td>0.727159</td>
238
-
<td>0.518634</td>
239
-
<td>0.059961</td>
240
-
<td>0.049232</td>
241
-
<td>0.060504</td>
242
-
<td>0.671311</td>
250
+
<td>0.528651</td>
251
+
<td>0.727084</td>
252
+
<td>0.517873</td>
253
+
<td>0.059852</td>
254
+
<td>0.049072</td>
255
+
<td>0.060409</td>
256
+
<td>0.676336</td>
243
257
</tr>
244
258
<tr>
245
259
<th>4</th>
246
260
<td>41 days</td>
247
-
<td>0.536078</td>
248
-
<td>0.732174</td>
249
-
<td>0.519585</td>
250
-
<td>0.060036</td>
251
-
<td>0.049389</td>
252
-
<td>0.060641</td>
253
-
<td>0.678849</td>
261
+
<td>0.536149</td>
262
+
<td>0.732222</td>
263
+
<td>0.518843</td>
264
+
<td>0.059927</td>
265
+
<td>0.049135</td>
266
+
<td>0.060548</td>
267
+
<td>0.681361</td>
268
+
</tr>
269
+
</tbody>
270
+
</table>
271
+
</div>
272
+
273
+
274
+
275
+
```python
276
+
# Python
277
+
from prophet.diagnostics import register_performance_metric, rolling_mean_by_h
278
+
import numpy as np
279
+
@register_performance_metric
280
+
defmase(df, w):
281
+
"""Mean absolute scale error
282
+
283
+
Parameters
284
+
----------
285
+
df: Cross-validation results dataframe.
286
+
w: Aggregation window size.
287
+
288
+
Returns
289
+
-------
290
+
Dataframe with columns horizon and mase.
291
+
"""
292
+
e = (df['y'] - df['yhat'])
293
+
d = np.abs(np.diff(df['y'])).sum()/(df['y'].shape[0]-1)
The size of the rolling window in the figure can be changed with the optional argument `rolling_window`, which specifies the proportion of forecasts to use in each rolling window. The default is 0.1, corresponding to 10% of rows from `df_cv` included in each window; increasing this will lead to a smoother average curve in the figure. The `initial` period should be long enough to capture all of the components of the model, in particular seasonalities and extra regressors: at least a year for yearly seasonality, at least a week for weekly seasonality, etc.
0 commit comments