def plot_predict(self, h=5, past_values=20, intervals=True, **kwargs):      
        """ Makes forecast with the estimated model

        Parameters
        ----------
        h : int (default : 5)
            How many steps ahead would you like to forecast?

        past_values : int (default : 20)
            How many past observations to show on the forecast graph?

        intervals : Boolean
            Would you like to show prediction intervals for the forecast?

        Returns
        ----------
        - Plot of the forecast
        """
        import matplotlib.pyplot as plt
        import seaborn as sns

        figsize = kwargs.get('figsize',(10,7))
        nsims = kwargs.get('nsims', 200)

        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            # Retrieve data, dates and (transformed) latent variables   
            if self.latent_variables.estimation_method in ['M-H']:
                lower_final = 0
                upper_final = 0
                plot_values_final = 0
                date_index = self.shift_dates(h)
                plot_index = date_index[-h-past_values:]

                for i in range(nsims):

                    t_params = self.draw_latent_variables(nsims=1).T[0]
                    a, P = self._forecast_model(t_params, h)

                    plot_values = a[0][-h-past_values:]
                    forecasted_values = a[0][-h:]

                    lower = forecasted_values - 1.96*np.power(P[0][0][-h:] + self.latent_variables.z_list[0].prior.transform(t_params[0]),0.5)
                    upper = forecasted_values + 1.96*np.power(P[0][0][-h:] + self.latent_variables.z_list[0].prior.transform(t_params[0]),0.5)
                    lower_final += np.append(plot_values[-h-1], lower)
                    upper_final += np.append(plot_values[-h-1], upper)
                    plot_values_final += plot_values

                plot_values_final = plot_values_final / nsims
                lower_final = lower_final / nsims
                upper_final = upper_final / nsims

                plt.figure(figsize=figsize)
                if intervals == True:
                    plt.fill_between(date_index[-h-1:], lower_final, upper_final, alpha=0.2)            

                plt.plot(plot_index, plot_values_final)
                plt.title("Forecast for " + self.data_name)
                plt.xlabel("Time")
                plt.ylabel(self.data_name)
                plt.show()
            else:
                a, P = self._forecast_model(self.latent_variables.get_z_values(),h)
                date_index = self.shift_dates(h)
                plot_values = a[0][-h-past_values:]
                forecasted_values = a[0][-h:]

                lower = forecasted_values - 1.96*np.power(P[0][0][-h:] + self.latent_variables.z_list[0].prior.transform(self.latent_variables.get_z_values()[0]),0.5)
                upper = forecasted_values + 1.96*np.power(P[0][0][-h:] + self.latent_variables.z_list[0].prior.transform(self.latent_variables.get_z_values()[0]),0.5)
                lower = np.append(plot_values[-h-1],lower)
                upper = np.append(plot_values[-h-1],upper)

                plot_index = date_index[-h-past_values:]

                plt.figure(figsize=figsize)
                if intervals == True:
                    plt.fill_between(date_index[-h-1:], lower, upper, alpha=0.2)            

                plt.plot(plot_index,plot_values)
                plt.title("Forecast for " + self.data_name)
                plt.xlabel("Time")
                plt.ylabel(self.data_name)
                plt.show()
def plot_predict ( self , h = 5 , past_values = 20 , intervals = True , ** kwargs ) : import matplotlib . pyplot as plt import seaborn as sns figsize = kwargs . get ( 'figsize' , ( 10 , 7 ) ) nsims = kwargs . get ( 'nsims' , 200 ) if self . latent_variables . estimated is False : raise Exception ( "No latent variables estimated!" ) else : if self . latent_variables . estimation_method in [ 'M-H' ] : lower_final = 0 upper_final = 0 plot_values_final = 0 date_index = self . shift_dates ( h ) plot_index = date_index [ - h - past_values : ] for i in range ( nsims ) : t_params = self . draw_latent_variables ( nsims = 1 ) . T [ 0 ] a , P = self . _forecast_model ( t_params , h ) plot_values = a [ 0 ] [ - h - past_values : ] forecasted_values = a [ 0 ] [ - h : ] lower = forecasted_values - 1.96 * np . power ( P [ 0 ] [ 0 ] [ - h : ] + self . latent_variables . z_list [ 0 ] . prior . transform ( t_params [ 0 ] ) , 0.5 ) upper = forecasted_values + 1.96 * np . power ( P [ 0 ] [ 0 ] [ - h : ] + self . latent_variables . z_list [ 0 ] . prior . transform ( t_params [ 0 ] ) , 0.5 ) lower_final += np . append ( plot_values [ - h - 1 ] , lower ) upper_final += np . append ( plot_values [ - h - 1 ] , upper ) plot_values_final += plot_values plot_values_final = plot_values_final / nsims lower_final = lower_final / nsims upper_final = upper_final / nsims plt . figure ( figsize = figsize ) if intervals == True : plt . fill_between ( date_index [ - h - 1 : ] , lower_final , upper_final , alpha = 0.2 ) plt . plot ( plot_index , plot_values_final ) plt . title ( "Forecast for " + self . data_name ) plt . xlabel ( "Time" ) plt . ylabel ( self . data_name ) plt . show ( ) else : a , P = self . _forecast_model ( self . latent_variables . get_z_values ( ) , h ) date_index = self . shift_dates ( h ) plot_values = a [ 0 ] [ - h - past_values : ] forecasted_values = a [ 0 ] [ - h : ] lower = forecasted_values - 1.96 * np . power ( P [ 0 ] [ 0 ] [ - h : ] + self . latent_variables . z_list [ 0 ] . prior . transform ( self . latent_variables . get_z_values ( ) [ 0 ] ) , 0.5 ) upper = forecasted_values + 1.96 * np . power ( P [ 0 ] [ 0 ] [ - h : ] + self . latent_variables . z_list [ 0 ] . prior . transform ( self . latent_variables . get_z_values ( ) [ 0 ] ) , 0.5 ) lower = np . append ( plot_values [ - h - 1 ] , lower ) upper = np . append ( plot_values [ - h - 1 ] , upper ) plot_index = date_index [ - h - past_values : ] plt . figure ( figsize = figsize ) if intervals == True : plt . fill_between ( date_index [ - h - 1 : ] , lower , upper , alpha = 0.2 ) plt . plot ( plot_index , plot_values ) plt . title ( "Forecast for " + self . data_name ) plt . xlabel ( "Time" ) plt . ylabel ( self . data_name ) plt . show ( )
Makes forecast with the estimated model

        Parameters
        ----------
        h : int (default : 5)
            How many steps ahead would you like to forecast?

        past_values : int (default : 20)
            How many past observations to show on the forecast graph?

        intervals : Boolean
            Would you like to show prediction intervals for the forecast?

        Returns
        ----------
        - Plot of the forecast