# Demo Notebook for BART in PyMC

**URL:** <https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483>\
**Category:** Sharing\
**Created:** [December 27, 2020, 2:11am UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483 "2020-12-27T02:11:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![adlauretig](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@adlauretig](https://discourse.pymc.io/u/adlauretig)\
**Post date:** [December 27, 2020, 2:11am UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/1 "2020-12-27T02:11:28Z")

</div>

Hi everyone,

I put together a _very_ minimalist notebook w/an example of BART in PyMC 3.10. I simulated some data, fit the model, and checked accuracy (using MSE). It seems like the n\_eff for BART params is low, I don’t know if that’s by design, or an issue with my implementation.

Anyways I hope this is helpful to people, feel free to poke through it: [https://github.com/adamlauretig/pymc\_bart/blob/master/pymc\_bart.ipynb](https://github.com/adamlauretig/pymc_bart/blob/master/pymc_bart.ipynb)

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [December 27, 2020, 12:37pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/2 "2020-12-27T12:37:18Z")

</div>

Thanks @adlauretig, and well done!  
Pinging @aloctavodia, as he’s our in-house BART expert – we even started calling him Bart internally 🤷‍♂️ I’m guessing he’ll be interested 😉

---

<div class="post-metadata">

**Author:** ![twiecki](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/twiecki/32/6930_2.png) [@twiecki](https://discourse.pymc.io/u/twiecki)\
**Post date:** [November 8, 2021, 3:40pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/3 "2021-11-08T15:40:30Z")

</div>

This is great @adlauretig, are you interested in contributing this to pymc-examples? [GitHub - pymc-devs/pymc-examples: Examples of PyMC models, including a library of Jupyter notebooks.](https://github.com/pymc-devs/pymc-examples)

---

<div class="post-metadata">

**Author:** ![keck343](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/keck343/32/5109_2.png) [@keck343](https://discourse.pymc.io/u/keck343)\
**Post date:** [May 2, 2022, 5:29pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/4 "2022-05-02T17:29:04Z")

</div>

Hello! I was wondering why v4.0.0.6b doesn’t have pm.BART() anymore and if that’s a permanent change. I’ve been utilizing this demo notebook which works on PyMC3 v4.0.0b2: [Bayesian Additive Regression Trees: Introduction — PyMC documentation](https://docs.pymc.io/projects/examples/en/latest/BART/BART_introduction.html) but not on v4.0.0b6 (there’s no pm.BART)

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [May 2, 2022, 8:30pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/5 "2022-05-02T20:30:31Z")

</div>

BART is now part of [pymc-experimental](https://pymc-experimental.readthedocs.io/en/latest/). Installation and imports is different but usage after that is not. Would you be interested in updating the example notebook @keck343 ?

---

<div class="post-metadata">

**Author:** ![keck343](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/keck343/32/5109_2.png) [@keck343](https://discourse.pymc.io/u/keck343)\
**Post date:** [May 2, 2022, 11:43pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/6 "2022-05-02T23:43:37Z")

</div>

Yes! I could do that. Would I just update it and create a pull request?

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [May 3, 2022, 3:07am UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/7 "2022-05-03T03:07:44Z")

</div>

Yes, thanks!

here is the github repository in case it helps: [GitHub - pymc-devs/pymc-examples: Examples of PyMC models, including a library of Jupyter notebooks.](https://github.com/pymc-devs/pymc-examples). Do not hesitate to ask here or on github if you have any doubts

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [May 7, 2022, 3:16pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/8 "2022-05-07T15:16:10Z")

</div>

@keck343 if you prefer you can also attend [office hours](https://discourse.pymc.io/t/pymc-office-hours-may-7th-pst/9318) to ask questions on getting started contributing

---

<div class="post-metadata">

**Author:** ![keck343](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/keck343/32/5109_2.png) [@keck343](https://discourse.pymc.io/u/keck343)\
**Post date:** [May 18, 2022, 11:36pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/9 "2022-05-18T23:36:01Z")

</div>

@OriolAbril I’m sorry I couldn’t make it to the office hours. Something changed from the pm.BART to pmx.BART implementation that makes it so that  
`pmx.bart.predict(idata_coal, rng, size=2)` throws an error  
`AttributeError: 'NoneType' object has no attribute 'shape'`

that I haven’t been able to figure out. I’ll try to make it to the next office hours!

idata\_coal is arviz.data.inference\_data.InferenceData and I’ve tried downgrading arviz to the same one in the original notebook to no avail. The BART example notebook runs on version on PyMC3 v4.0.0b2 but this line fails on PyMC3 v4.0.0b6 and install pymc-experimental via pip:

`pip install git+https://github.com/pymc-devs/pymc-experimental`

---

<div class="post-metadata">

**Author:** ![ricardoV94](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ricardov94/32/5775_2.png) [@ricardoV94](https://discourse.pymc.io/u/ricardoV94)\
**Post date:** [May 19, 2022, 6:14am UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/10 "2022-05-19T06:14:31Z")

</div>

Maybe @aloctavodia can help with that error?

---

<div class="post-metadata">

**Author:** ![aloctavodia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/aloctavodia/32/8642_2.png) [@aloctavodia](https://discourse.pymc.io/u/aloctavodia)\
**Post date:** [May 20, 2022, 4:15pm UTC](https://discourse.pymc.io/t/demo-notebook-for-bart-in-pymc/6483/11 "2022-05-20T16:15:50Z")

</div>

Hi,

Now that line should be `plt.step(x_data, np.exp(pmx.bart.predict(idata_coal, rng, x_data, size=2).T));` i.e. you need to pass your “X”.

also in the next cell, you will need to do: `plt.step(x_data[:, 0], [bart_trees[0, 0, i].item().predict(x) for x in x_data])`

I am going to update the notebook ASAP.
