You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this section we want to show how to do out-of-sample predictions with BART. We are going to use the same dataset as before, but this time we are going to split the data into a training and a test set. We are going to use the training set to fit the model and the test set to evaluate the model.
189
+
As this is a time series problem we need to make sure we do not shuffle the data. Hence we do the split using the `hour` feature.
Now, we fit the same model as above but this time using a *shared variable* for the covariatates so that we can then replace them to generate the out of sample predictions.
205
+
206
+
```{code-cell} ipython3
207
+
with pm.Model() as model_bikes_train_test:
208
+
X = pm.MutableData("X", X_train)
209
+
Y = Y_train
210
+
α = pm.Exponential("α", 1 / 10)
211
+
μ = pmb.BART("μ", X, Y)
212
+
y = pm.NegativeBinomial("y", mu=pm.math.abs(μ), alpha=α, observed=Y, shape=μ.shape)
The out-of-sample predictions look a bit odd. Why? Well, note that in the variable importance ranking from the initial model we saw that `hour` was the most important predictor. On the other hand, our training data just sees `hour` values until $19$. As BART learns how to partition the (training) data, it can not differentiate between `hour` values between $20$ and $22$ for example. It just cares that both values are greater that $19$. This is very important to understand when using BART! This explains why one should not use BART for time series forecasting if there is a trend component. In this case it is better to detrend the data first, model the remainder with BART and model the trend with a different model.
283
+
284
+
+++
285
+
182
286
## Authors
183
287
* Authored by Osvaldo Martin in Dec, 2021 ([pymc-examples#259](https://github.com/pymc-devs/pymc-examples/pull/259))
184
288
* Updated by Osvaldo Martin in May, 2022 ([pymc-examples#323](https://github.com/pymc-devs/pymc-examples/pull/323))
185
289
* Updated by Osvaldo Martin in Sep, 2022
186
290
* Updated by Osvaldo Martin in Nov, 2022
291
+
* Juan Orduz added out-of-sample section in Jan, 2023
0 commit comments