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 95% 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))

        if self.latent_variables.estimated is False:
            raise Exception("No latent variables estimated!")
        else:
            # Retrieve data, dates and (transformed) latent variables
            scale, shape, skewness = self._get_scale_and_shape(self.latent_variables.get_z_values(transformed=True))
            previous_value = self.data[-1]  
            forecasted_values = np.ones(h)*self.states[-1]  
            date_index = self.shift_dates(h)
            simulations = 10000
            sim_vector = np.zeros([simulations,h])
            t_params = self.transform_z()

            for n in range(0,simulations):  
                rnd_q = np.random.normal(0,np.sqrt(self.latent_variables.get_z_values(transformed=True)[0]),h) 
                exp = forecasted_values.copy()

                for t in range(0,h):
                    if t == 0:
                        exp[t] = forecasted_values[t] + rnd_q[t]
                    else:
                        exp[t] = exp[t-1] + rnd_q[t]

                sim_vector[n] = self.family.draw_variable(loc=self.link(exp),shape=shape,scale=scale,skewness=skewness,nsims=exp.shape[0])

            sim_vector = np.transpose(sim_vector)

            forecasted_values = self.link(forecasted_values)

            if self.model_name2 == 'Skewt':
                forecasted_values = forecasted_values + ((t_params[-3] - (1.0/t_params[-3]))*t_params[-2]*gas.SkewtScore.tv_variate_exp(t_params[-1]))

            plt.figure(figsize=figsize) 

            if intervals == True:
                plt.fill_between(date_index[-h-1:], np.insert([np.percentile(i,5) for i in sim_vector],0,previous_value), 
                    np.insert([np.percentile(i,95) for i in sim_vector],0,previous_value), alpha=0.2,label="95 C.I.")   

            plot_values = np.append(self.data[-past_values:],forecasted_values)
            plot_index = date_index[-h-past_values:]

            plt.plot(plot_index,plot_values,label=self.data_name)
            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 ) ) if self . latent_variables . estimated is False : raise Exception ( "No latent variables estimated!" ) else : scale , shape , skewness = self . _get_scale_and_shape ( self . latent_variables . get_z_values ( transformed = True ) ) previous_value = self . data [ - 1 ] forecasted_values = np . ones ( h ) * self . states [ - 1 ] date_index = self . shift_dates ( h ) simulations = 10000 sim_vector = np . zeros ( [ simulations , h ] ) t_params = self . transform_z ( ) for n in range ( 0 , simulations ) : rnd_q = np . random . normal ( 0 , np . sqrt ( self . latent_variables . get_z_values ( transformed = True ) [ 0 ] ) , h ) exp = forecasted_values . copy ( ) for t in range ( 0 , h ) : if t == 0 : exp [ t ] = forecasted_values [ t ] + rnd_q [ t ] else : exp [ t ] = exp [ t - 1 ] + rnd_q [ t ] sim_vector [ n ] = self . family . draw_variable ( loc = self . link ( exp ) , shape = shape , scale = scale , skewness = skewness , nsims = exp . shape [ 0 ] ) sim_vector = np . transpose ( sim_vector ) forecasted_values = self . link ( forecasted_values ) if self . model_name2 == 'Skewt' : forecasted_values = forecasted_values + ( ( t_params [ - 3 ] - ( 1.0 / t_params [ - 3 ] ) ) * t_params [ - 2 ] * gas . SkewtScore . tv_variate_exp ( t_params [ - 1 ] ) ) plt . figure ( figsize = figsize ) if intervals == True : plt . fill_between ( date_index [ - h - 1 : ] , np . insert ( [ np . percentile ( i , 5 ) for i in sim_vector ] , 0 , previous_value ) , np . insert ( [ np . percentile ( i , 95 ) for i in sim_vector ] , 0 , previous_value ) , alpha = 0.2 , label = "95 C.I." ) plot_values = np . append ( self . data [ - past_values : ] , forecasted_values ) plot_index = date_index [ - h - past_values : ] plt . plot ( plot_index , plot_values , label = self . data_name ) 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 95% prediction intervals for the forecast?

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