Exemple #1
0
def simple_exponential_smoothing_ci(stochastic_process):
    N, t, alpha = 200, 160, 0.5
    if stochastic_process == "GP":
        x0 = 20
        realisations = pd.Series(sample_gaussian_process(20, 5, N), range(N))
    elif stochastic_process == "RW":
        x0 = 0
        realisations = pd.Series(list(sample_random_walk(0, N)), range(N))
    else:
        quit()
    mod = ExponentialSmoothing(realisations[:t + 1],
                               initialization_method='known',
                               initial_level=x0).fit(disp=False)
    print(mod.summary())
    forecasts = mod.get_forecast(N - (t + 1))
    forecasts_ci = forecasts.conf_int(alpha=0.05)
    plot_ci(realisations,
            pd.Series(np.nan, range(t + 1)).append(forecasts.predicted_mean),
            forecasts_ci, alpha)
    if stochastic_process == "GP":
        plt.savefig('/Users/gwren/Downloads/36_ses_prediction_intervals.svg',
                    format='svg')
    elif stochastic_process == "RW":
        plt.savefig('/Users/gwren/Downloads/37_ses_gaussian_random_walk.svg',
                    format='svg')
    else:
        quit()
    py.show()
def holt_ci():
    N, t = 200, 160
    realisations = pd.Series(list(sample_random_walk(0, 0.1, N)), range(N))
    mod = ExponentialSmoothing(
        realisations[:t + 1], trend=True,
        initialization_method='estimated').fit(disp=False)
    print(mod.summary())
    forecasts = mod.get_forecast(N - (t + 1))
    forecasts_ci = forecasts.conf_int(alpha=0.05)
    plot_ci(realisations,
            pd.Series(np.nan, range(t + 1)).append(forecasts.predicted_mean),
            forecasts_ci)
    py.show()