Rahul Anand
Rahul Anand

Reputation: 573

Calculation of lower and upper confidence interval with GluonTs

I am using GluonTs for monthly forecasts and need to calculate upper and lower confidence intervals. GluonTs has plot() function which enables us to plot it using forecast class but i want to use my own plot function for which confidence intervals are required.

  1. Using GluonTs Forecast class gives us a confidence interval but it's a single value. How do we use this to get yhat_upper and yhat_lower ?

    np.percentile(forecasts_multivariate[0].samples.sum(axis = 1), 90)

  2. Using basic t test. But this is not giving correct results!. It returns upper and lower confidence intervals

    import scipy.stats as st

    st.t.interval(alpha=0.95, df=len(pred) - 1, loc=np.mean(pred), scale=st.sem(pred))

How do we get upper and lower CI with GluonTs?

Upvotes: 1

Views: 498

Answers (1)

Rahul Anand
Rahul Anand

Reputation: 573

import pandas as pd
df_bands = pd.DataFrame(forecasts[0].samples, columns = list(df_final.index[-7:].values), dtype = float)
lower_band_90 = df_bands.quantile(q=0.05, axis=0)
upper_band_90 = df_bands.quantile(q=0.95, axis=0)
    
lower_band_50 = df_bands.quantile(q=0.25, axis=0)
upper_band_50 = df_bands.quantile(q=0.75, axis=0)

Upvotes: 0

Related Questions