Skip to content

Commit 9f913bc

Browse files
committed
+ ran precommit on new NB, created myst file
1 parent c3d5f01 commit 9f913bc

File tree

3 files changed

+1703
-109
lines changed

3 files changed

+1703
-109
lines changed

examples/generalized_linear_models/GLM-missing-values-in-covariates.ipynb

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@
146146
},
147147
"outputs": [],
148148
"source": [
149+
"# suppress seaborn, it's far too chatty\n",
150+
"import warnings # #noqa\n",
151+
"\n",
149152
"from copy import deepcopy\n",
150153
"\n",
151154
"import arviz as az\n",
@@ -157,9 +160,7 @@
157160
"\n",
158161
"from pymc.testing import assert_no_rvs\n",
159162
"\n",
160-
"# suppress seaborn, it's far too chatty\n",
161-
"import warnings # #noqa\n",
162-
"warnings.simplefilter(action=\"ignore\", category=FutureWarning) # noqa\n",
163+
"warnings.simplefilter(action=\"ignore\", category=FutureWarning) # noqa\n",
163164
"import seaborn as sns"
164165
]
165166
},
@@ -859,6 +860,7 @@
859860
" _ = f.suptitle(\"Univariate numerics with NaN count noted\")\n",
860861
" _ = f.tight_layout()\n",
861862
"\n",
863+
"\n",
862864
"plot_univariate_violin(df, fts=[\"y\"])"
863865
]
864866
},
@@ -952,7 +954,7 @@
952954
" fit_reg=True,\n",
953955
" height=4,\n",
954956
" aspect=0.75,\n",
955-
" facet_kws={'sharex':False}\n",
957+
" facet_kws={\"sharex\": False},\n",
956958
")\n",
957959
"_ = g.fig.suptitle(\"Bivariate plots of `y` vs fts `a`, `b`, `c`, `d`\")\n",
958960
"_ = g.fig.tight_layout()"
@@ -2131,9 +2133,9 @@
21312133
"FTS_XJ = [\"intercept\", \"a\", \"b\", \"c\", \"d\"]\n",
21322134
"\n",
21332135
"COORDS = dict(\n",
2134-
" xj_nm=FTS_XJ, # these are the names of the features\n",
2135-
" oid=dfrawx_train.index.values # these are the observation_ids\n",
2136-
" )\n",
2136+
" xj_nm=FTS_XJ, # these are the names of the features\n",
2137+
" oid=dfrawx_train.index.values, # these are the observation_ids\n",
2138+
")\n",
21372139
"\n",
21382140
"with pm.Model(coords=COORDS) as mdl0:\n",
21392141
" # 0. create (Mutable)Data containers for obs (Y, X)\n",
@@ -2344,7 +2346,7 @@
23442346
}
23452347
],
23462348
"source": [
2347-
"GRP = 'prior'\n",
2349+
"GRP = \"prior\"\n",
23482350
"kws = dict(samples=2000, return_inferencedata=True, random_seed=42)\n",
23492351
"with mdl0:\n",
23502352
" id0 = pm.sample_prior_predictive(var_names=RVS_PPC + RVS_PRIOR, **kws)"
@@ -2392,6 +2394,7 @@
23922394
" _ = f.suptitle(f\"In-sample {grp.title()} PPC Retrodictive KDE on `{ynm}` - `{mdlnm}`\")\n",
23932395
" return f\n",
23942396
"\n",
2397+
"\n",
23952398
"f = plot_ppc_retrodictive(id0, grp=GRP, rvs=[\"yhat\"], mdlnm=\"mdl0\", ynm=\"y\")"
23962399
]
23972400
},
@@ -2562,7 +2565,7 @@
25622565
}
25632566
],
25642567
"source": [
2565-
"GRP = 'posterior'\n",
2568+
"GRP = \"posterior\"\n",
25662569
"with mdl0:\n",
25672570
" id0.extend(pm.sample(**SAMPLE_KWS), join=\"right\")\n",
25682571
" id0.extend(\n",
@@ -2972,6 +2975,7 @@
29722975
" _ = f.tight_layout()\n",
29732976
" return f\n",
29742977
"\n",
2978+
"\n",
29752979
"f = plot_forest(id0, grp=GRP, rvs=[\"beta_j\"], mdlnm=\"mdl0\")"
29762980
]
29772981
},
@@ -3371,21 +3375,23 @@
33713375
"FTS_XJ = [\"intercept\", \"a\", \"b\"]\n",
33723376
"FTS_XK = [\"c\", \"d\"]\n",
33733377
"COORDS = dict(\n",
3374-
" xj_nm=FTS_XJ, # names of the features j\n",
3375-
" xk_nm=FTS_XK, # names of the features k\n",
3376-
" oid=dfx_train.index.values # these are the observation_ids\n",
3377-
" )\n",
3378+
" xj_nm=FTS_XJ, # names of the features j\n",
3379+
" xk_nm=FTS_XK, # names of the features k\n",
3380+
" oid=dfx_train.index.values, # these are the observation_ids\n",
3381+
")\n",
33783382
"\n",
33793383
"with pm.Model(coords=COORDS) as mdla:\n",
33803384
" # 0. create (Mutable)Data containers for obs (Y, X)\n",
33813385
" y = pm.Data(\"y\", dfx_train[ft_y].values, dims=\"oid\")\n",
33823386
" xj = pm.Data(\"xj\", dfx_train[FTS_XJ].values, dims=(\"oid\", \"xj_nm\"))\n",
33833387
"\n",
33843388
" # 1. create auto-imputing likelihood for missing data values\n",
3385-
" # NOTE: there's no way to put a nan-containing array (nor a np.masked_array) \n",
3389+
" # NOTE: there's no way to put a nan-containing array (nor a np.masked_array)\n",
33863390
" # into a pm.Data, so dfx_train[FTS_XK].values has to go in directly\n",
33873391
" xk_mu = pm.Normal(\"xk_mu\", mu=0.0, sigma=1, dims=\"xk_nm\")\n",
3388-
" xk = pm.Normal(\"xk\", mu=xk_mu, sigma=1.0, observed=dfx_train[FTS_XK].values, dims=(\"oid\", \"xk_nm\"))\n",
3392+
" xk = pm.Normal(\n",
3393+
" \"xk\", mu=xk_mu, sigma=1.0, observed=dfx_train[FTS_XK].values, dims=(\"oid\", \"xk_nm\")\n",
3394+
" )\n",
33893395
"\n",
33903396
" # 2. define priors for contiguous and auto-imputed data\n",
33913397
" b_s = pm.Gamma(\"beta_sigma\", alpha=10, beta=10) # E ~ 1\n",
@@ -3709,7 +3715,7 @@
37093715
}
37103716
],
37113717
"source": [
3712-
"GRP = 'prior'\n",
3718+
"GRP = \"prior\"\n",
37133719
"kws = dict(samples=2000, return_inferencedata=True, random_seed=42)\n",
37143720
"with mdla:\n",
37153721
" ida = pm.sample_prior_predictive(\n",
@@ -3976,7 +3982,7 @@
39763982
}
39773983
],
39783984
"source": [
3979-
"GRP = 'posterior'\n",
3985+
"GRP = \"posterior\"\n",
39803986
"with mdla:\n",
39813987
" ida.extend(pm.sample(**SAMPLE_KWS), join=\"right\")\n",
39823988
" ida.extend(\n",
@@ -5228,10 +5234,12 @@
52285234
"\n",
52295235
" # same code as above for mdla\n",
52305236
" # 1. create auto-imputing likelihood for missing data values\n",
5231-
" # NOTE: there's no way to put a nan-containing array (nor a np.masked_array) \n",
5237+
" # NOTE: there's no way to put a nan-containing array (nor a np.masked_array)\n",
52325238
" # into a pm.Data, so dfx_holdout[FTS_XK].values has to go in directly\n",
52335239
" xk_mu = pm.Normal(\"xk_mu\", mu=0.0, sigma=1, dims=\"xk_nm\")\n",
5234-
" xk = pm.Normal(\"xk\", mu=xk_mu, sigma=1.0, observed=dfx_holdout[FTS_XK].values, dims=(\"oid\", \"xk_nm\"))\n",
5240+
" xk = pm.Normal(\n",
5241+
" \"xk\", mu=xk_mu, sigma=1.0, observed=dfx_holdout[FTS_XK].values, dims=(\"oid\", \"xk_nm\")\n",
5242+
" )\n",
52355243
"\n",
52365244
" # 2. define priors for contiguous and auto-imputed data\n",
52375245
" b_s = pm.Gamma(\"beta_sigma\", alpha=10, beta=10) # E ~ 1\n",

0 commit comments

Comments
 (0)