Skip to content

Commit 5715231

Browse files
committed
simplify scatter plot code with seaborn
1 parent 63cd4a7 commit 5715231

File tree

2 files changed

+232
-248
lines changed

2 files changed

+232
-248
lines changed

examples/generalized_linear_models/GLM-simpsons-paradox.ipynb

Lines changed: 227 additions & 235 deletions
Large diffs are not rendered by default.

examples/generalized_linear_models/GLM-simpsons-paradox.myst.md

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ jupytext:
55
format_name: myst
66
format_version: 0.13
77
kernelspec:
8-
display_name: pymc_env
8+
display_name: Python 3
99
language: python
10-
name: pymc_env
10+
name: python3
1111
---
1212

1313
(GLM-simpsons-paradox)=
@@ -34,6 +34,7 @@ import matplotlib.pyplot as plt
3434
import numpy as np
3535
import pandas as pd
3636
import pymc as pm
37+
import seaborn as sns
3738
import xarray as xr
3839
```
3940

@@ -82,16 +83,7 @@ display(data)
8283
And we can visualise this as below.
8384

8485
```{code-cell} ipython3
85-
:tags: [hide-input]
86-
87-
for i, group in enumerate(group_list):
88-
plt.scatter(
89-
data.query(f"group_idx=={i}").x,
90-
data.query(f"group_idx=={i}").y,
91-
color=f"C{i}",
92-
label=f"{group}",
93-
)
94-
plt.legend(title="group");
86+
sns.scatterplot(data=data, x="x", y="y", hue="group");
9587
```
9688

9789
The rest of the notebook will cover different ways that we can analyse this data using linear models.
@@ -488,7 +480,7 @@ with hierarchical:
488480
idata = pm.sample(tune=4000, target_accept=0.99, random_seed=rng)
489481
```
490482

491-
:::{note}
483+
:::{caution}
492484
Note that despite having a longer tune period and increased `target_accept`, this model can still generate a low number of divergent samples. If the reader is interested, you can explore the a "reparameterisation trick" is used by setting the flag `non_centered=True`. See the blog post [Why hierarchical models are awesome, tricky, and Bayesian](https://twiecki.io/blog/2017/02/08/bayesian-hierchical-non-centered/) by Thomas Wiecki for more information on this.
493485
:::
494486

0 commit comments

Comments
 (0)