tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.23k stars 1.09k forks source link

where to include external regressor while forecasting incase of multivariate analysis #697

Open yug95 opened 4 years ago

yug95 commented 4 years ago

where to include external regressor while forecasting incase of multivariate analysis.

temperature_effect = sts.LinearRegression(design_matrix=tf.reshape(temperature - np.mean(temperature),(-1, 1)), name='temperature_effect')

but while forecasting ,

tfp.sts.forecast(model,observed_time_series,parameter_samples=q_samplesco2,num_steps_forecast=1)

where to include temperature_effect here ?

davmre commented 4 years ago

You just need to ensure that the model you forecast with has a design matrix covering both the observed and forecasted timesteps. That is, you'd build a model including a component along the lines of

sts.LinearRegression(
  design_matrix=tf.concat([temperature_for_observed_timesteps,
                           temperature_for_forecast_timesteps], axis=-2),
  name='temperature_effect')

(ignoring any centering and reshaping logic) and then pass that model to the forecast method.

If you don't have access to future values of the external regressor when you first build the model, a useful pattern is to encapsulate model building in a method def build_model(observed_time_series, design_matrix) that returns a StructuralTimeSeries model object. Then you can build an initial model with just the observed time steps in order to fit parameters, and then remake the model later once you have the regressors for the forecast steps on hand.

yug95 commented 4 years ago

@davmre Thank you much for quick response. it is working