|
2876 | 2876 | "sm_model.summary()"
|
2877 | 2877 | ]
|
2878 | 2878 | },
|
2879 |
| - { |
2880 |
| - "cell_type": "code", |
2881 |
| - "execution_count": null, |
2882 |
| - "metadata": { |
2883 |
| - "collapsed": false |
2884 |
| - }, |
2885 |
| - "outputs": [], |
2886 |
| - "source": [ |
2887 |
| - "mean_sea_level[\"mean_global\"].plot()\n", |
2888 |
| - "sm_model.fittedvalues.plot(label=\"OLS prediction\")\n", |
2889 |
| - "plt.legend(loc=\"upper left\")" |
2890 |
| - ] |
2891 |
| - }, |
2892 | 2879 | {
|
2893 | 2880 | "cell_type": "code",
|
2894 | 2881 | "execution_count": null,
|
|
2899 | 2886 | "source": [
|
2900 | 2887 | "plt.figure(figsize=LARGE_FIGSIZE)\n",
|
2901 | 2888 | "mean_sea_level[\"mean_global\"].plot()\n",
|
2902 |
| - "pd_model.predict().plot(label=\"OLS prediction\")\n", |
| 2889 | + "sm_model.fittedvalues.plot(label=\"OLS prediction\")\n", |
2903 | 2890 | "plt.legend(loc=\"upper left\")"
|
2904 | 2891 | ]
|
2905 | 2892 | },
|
|
3288 | 3275 | "An auto-regresssive model fits existing data and build a (potentially predictive) model of the data fitted. We use the timeseries analysis (`tsa`) submodule of `statsmodels` to make out-of-sample predictions for the upcoming decades:"
|
3289 | 3276 | ]
|
3290 | 3277 | },
|
| 3278 | + { |
| 3279 | + "cell_type": "code", |
| 3280 | + "execution_count": null, |
| 3281 | + "metadata": { |
| 3282 | + "collapsed": true |
| 3283 | + }, |
| 3284 | + "outputs": [], |
| 3285 | + "source": [ |
| 3286 | + "from statsmodels.tsa.api import AR" |
| 3287 | + ] |
| 3288 | + }, |
3291 | 3289 | {
|
3292 | 3290 | "cell_type": "code",
|
3293 | 3291 | "execution_count": null,
|
|
3299 | 3297 | "import statsmodels as sm\n",
|
3300 | 3298 | "# Let's remove seasonal variations by resampling annually\n",
|
3301 | 3299 | "data = giss_temp_series.resample(\"A\").mean().to_timestamp()\n",
|
3302 |
| - "ar_model = sm.tsa.ar_model.AR(data, freq='A')\n", |
| 3300 | + "ar_model = AR(data, freq='A')\n", |
3303 | 3301 | "ar_res = ar_model.fit(maxlag=60, disp=True)"
|
3304 | 3302 | ]
|
3305 | 3303 | },
|
|
0 commit comments