Skip to content

Update ModelBuilder to show regression lines #538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/howto/linear_model_v1.nc
Binary file not shown.
344 changes: 35 additions & 309 deletions examples/howto/model_builder.ipynb

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions examples/howto/model_builder.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ jupytext:
format_name: myst
format_version: 0.13
kernelspec:
display_name: pymc5
display_name: pymc-dev
language: python
name: pymc5
name: python3
---

# Using ModelBuilder class for deploying PyMC models
Expand Down Expand Up @@ -37,6 +37,7 @@ import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import pymc as pm
import xarray as xr

from numpy.random import RandomState

Expand Down Expand Up @@ -269,14 +270,15 @@ After using the `predict()`, we can plot our data and see graphically how satisf

```{code-cell} ipython3
fig, ax = plt.subplots(figsize=(7, 7))
ax.plot(
x_pred,
pred_mean["y"],
"x",
label="predict",
)
posterior = az.extract(idata, num_samples=20)
x_plot = xr.DataArray(np.linspace(1, 2, 100))
y_plot = posterior["b"] * x_plot + posterior["a"]
Line2 = ax.plot(x_plot, y_plot.transpose(), color="C1")
Line1 = ax.plot(x_pred, pred_mean["y"], "x")
ax.set(title="Posterior predictive regression lines", xlabel="x", ylabel="y")
plt.legend(loc=0);
ax.legend(
handles=[Line1[0], Line2[0]], labels=["predicted average", "inferred regression line"], loc=0
);
```

```{code-cell} ipython3
Expand Down