Fix artifacts in diagnostics nb markdown

This commit is contained in:
Ben Letham 2020-08-20 11:20:47 -07:00
parent 5e6c6a02f8
commit 6284fc0264
5 changed files with 52 additions and 49 deletions

View file

@ -40,16 +40,12 @@ head(df.cv)
# Python
from fbprophet.diagnostics import cross_validation
df_cv = cross_validation(m, initial='730 days', period='180 days', horizon = '365 days')
```
```python
# Python
df_cv.head()
```
HBox(children=(FloatProgress(value=0.0, max=11.0), HTML(value='')))
<div>
@ -83,8 +79,8 @@ df_cv.head()
<th>0</th>
<td>2010-02-16</td>
<td>8.956828</td>
<td>8.479812</td>
<td>9.450908</td>
<td>8.460272</td>
<td>9.476844</td>
<td>8.242493</td>
<td>2010-02-15</td>
</tr>
@ -92,8 +88,8 @@ df_cv.head()
<th>1</th>
<td>2010-02-17</td>
<td>8.723230</td>
<td>8.213162</td>
<td>9.217637</td>
<td>8.208639</td>
<td>9.222179</td>
<td>8.008033</td>
<td>2010-02-15</td>
</tr>
@ -101,8 +97,8 @@ df_cv.head()
<th>2</th>
<td>2010-02-18</td>
<td>8.607021</td>
<td>8.119864</td>
<td>9.066214</td>
<td>8.106506</td>
<td>9.104792</td>
<td>8.045268</td>
<td>2010-02-15</td>
</tr>
@ -110,8 +106,8 @@ df_cv.head()
<th>3</th>
<td>2010-02-19</td>
<td>8.528870</td>
<td>8.088676</td>
<td>9.024842</td>
<td>8.061701</td>
<td>9.024450</td>
<td>7.928766</td>
<td>2010-02-15</td>
</tr>
@ -119,8 +115,8 @@ df_cv.head()
<th>4</th>
<td>2010-02-20</td>
<td>8.270872</td>
<td>7.740251</td>
<td>8.760655</td>
<td>7.773299</td>
<td>8.745526</td>
<td>7.745003</td>
<td>2010-02-15</td>
</tr>
@ -147,13 +143,6 @@ df.cv2 <- cross_validation(m, cutoffs = cutoffs, horizon = 365, units = 'days')
cutoffs = pd.to_datetime(['2013-02-15', '2013-08-15', '2014-02-15'])
df_cv2 = cross_validation(m, cutoffs=cutoffs, horizon='365 days')
```
HBox(children=(FloatProgress(value=0.0, max=3.0), HTML(value='')))
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.
@ -268,7 +257,7 @@ from fbprophet.plot import plot_cross_validation_metric
fig = plot_cross_validation_metric(df_cv, metric='mape')
```
![png](/prophet/static/diagnostics_files/diagnostics_15_0.png)
![png](/prophet/static/diagnostics_files/diagnostics_16_0.png)
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.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 65 KiB

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View file

@ -10,7 +10,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "622a0104e841488fae81864678a008b3",
"model_id": "0700e1522a544128889a6f25fa181c2b",
"version_major": 2,
"version_minor": 0
},
@ -175,13 +175,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"execution_count": 3,
"metadata": {
"output_hidden": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "da408f9d6cf940f3ab28dcc7114e629c",
"model_id": "d198a659eea54089876a9d87e61a09ff",
"version_major": 2,
"version_minor": 0
},
@ -198,7 +200,18 @@
"text": [
"\n"
]
},
}
],
"source": [
"from fbprophet.diagnostics import cross_validation\n",
"df_cv = cross_validation(m, initial='730 days', period='180 days', horizon = '365 days')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
@ -233,8 +246,8 @@
" <th>0</th>\n",
" <td>2010-02-16</td>\n",
" <td>8.956828</td>\n",
" <td>8.479812</td>\n",
" <td>9.450908</td>\n",
" <td>8.460272</td>\n",
" <td>9.476844</td>\n",
" <td>8.242493</td>\n",
" <td>2010-02-15</td>\n",
" </tr>\n",
@ -242,8 +255,8 @@
" <th>1</th>\n",
" <td>2010-02-17</td>\n",
" <td>8.723230</td>\n",
" <td>8.213162</td>\n",
" <td>9.217637</td>\n",
" <td>8.208639</td>\n",
" <td>9.222179</td>\n",
" <td>8.008033</td>\n",
" <td>2010-02-15</td>\n",
" </tr>\n",
@ -251,8 +264,8 @@
" <th>2</th>\n",
" <td>2010-02-18</td>\n",
" <td>8.607021</td>\n",
" <td>8.119864</td>\n",
" <td>9.066214</td>\n",
" <td>8.106506</td>\n",
" <td>9.104792</td>\n",
" <td>8.045268</td>\n",
" <td>2010-02-15</td>\n",
" </tr>\n",
@ -260,8 +273,8 @@
" <th>3</th>\n",
" <td>2010-02-19</td>\n",
" <td>8.528870</td>\n",
" <td>8.088676</td>\n",
" <td>9.024842</td>\n",
" <td>8.061701</td>\n",
" <td>9.024450</td>\n",
" <td>7.928766</td>\n",
" <td>2010-02-15</td>\n",
" </tr>\n",
@ -269,8 +282,8 @@
" <th>4</th>\n",
" <td>2010-02-20</td>\n",
" <td>8.270872</td>\n",
" <td>7.740251</td>\n",
" <td>8.760655</td>\n",
" <td>7.773299</td>\n",
" <td>8.745526</td>\n",
" <td>7.745003</td>\n",
" <td>2010-02-15</td>\n",
" </tr>\n",
@ -280,21 +293,19 @@
],
"text/plain": [
" ds yhat yhat_lower yhat_upper y cutoff\n",
"0 2010-02-16 8.956828 8.479812 9.450908 8.242493 2010-02-15\n",
"1 2010-02-17 8.723230 8.213162 9.217637 8.008033 2010-02-15\n",
"2 2010-02-18 8.607021 8.119864 9.066214 8.045268 2010-02-15\n",
"3 2010-02-19 8.528870 8.088676 9.024842 7.928766 2010-02-15\n",
"4 2010-02-20 8.270872 7.740251 8.760655 7.745003 2010-02-15"
"0 2010-02-16 8.956828 8.460272 9.476844 8.242493 2010-02-15\n",
"1 2010-02-17 8.723230 8.208639 9.222179 8.008033 2010-02-15\n",
"2 2010-02-18 8.607021 8.106506 9.104792 8.045268 2010-02-15\n",
"3 2010-02-19 8.528870 8.061701 9.024450 7.928766 2010-02-15\n",
"4 2010-02-20 8.270872 7.773299 8.745526 7.745003 2010-02-15"
]
},
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from fbprophet.diagnostics import cross_validation\n",
"df_cv = cross_validation(m, initial='730 days', period='180 days', horizon = '365 days')\n",
"df_cv.head()"
]
},
@ -321,7 +332,9 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"metadata": {
"output_hidden": true
},
"outputs": [
{
"data": {
@ -703,6 +716,7 @@
}
],
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3",
"language": "python",