|
146 | 146 | },
|
147 | 147 | "outputs": [],
|
148 | 148 | "source": [
|
| 149 | + "# suppress seaborn, it's far too chatty\n", |
| 150 | + "import warnings # #noqa\n", |
| 151 | + "\n", |
149 | 152 | "from copy import deepcopy\n",
|
150 | 153 | "\n",
|
151 | 154 | "import arviz as az\n",
|
|
157 | 160 | "\n",
|
158 | 161 | "from pymc.testing import assert_no_rvs\n",
|
159 | 162 | "\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", |
163 | 164 | "import seaborn as sns"
|
164 | 165 | ]
|
165 | 166 | },
|
|
859 | 860 | " _ = f.suptitle(\"Univariate numerics with NaN count noted\")\n",
|
860 | 861 | " _ = f.tight_layout()\n",
|
861 | 862 | "\n",
|
| 863 | + "\n", |
862 | 864 | "plot_univariate_violin(df, fts=[\"y\"])"
|
863 | 865 | ]
|
864 | 866 | },
|
|
952 | 954 | " fit_reg=True,\n",
|
953 | 955 | " height=4,\n",
|
954 | 956 | " aspect=0.75,\n",
|
955 |
| - " facet_kws={'sharex':False}\n", |
| 957 | + " facet_kws={\"sharex\": False},\n", |
956 | 958 | ")\n",
|
957 | 959 | "_ = g.fig.suptitle(\"Bivariate plots of `y` vs fts `a`, `b`, `c`, `d`\")\n",
|
958 | 960 | "_ = g.fig.tight_layout()"
|
|
2131 | 2133 | "FTS_XJ = [\"intercept\", \"a\", \"b\", \"c\", \"d\"]\n",
|
2132 | 2134 | "\n",
|
2133 | 2135 | "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", |
2137 | 2139 | "\n",
|
2138 | 2140 | "with pm.Model(coords=COORDS) as mdl0:\n",
|
2139 | 2141 | " # 0. create (Mutable)Data containers for obs (Y, X)\n",
|
|
2344 | 2346 | }
|
2345 | 2347 | ],
|
2346 | 2348 | "source": [
|
2347 |
| - "GRP = 'prior'\n", |
| 2349 | + "GRP = \"prior\"\n", |
2348 | 2350 | "kws = dict(samples=2000, return_inferencedata=True, random_seed=42)\n",
|
2349 | 2351 | "with mdl0:\n",
|
2350 | 2352 | " id0 = pm.sample_prior_predictive(var_names=RVS_PPC + RVS_PRIOR, **kws)"
|
|
2392 | 2394 | " _ = f.suptitle(f\"In-sample {grp.title()} PPC Retrodictive KDE on `{ynm}` - `{mdlnm}`\")\n",
|
2393 | 2395 | " return f\n",
|
2394 | 2396 | "\n",
|
| 2397 | + "\n", |
2395 | 2398 | "f = plot_ppc_retrodictive(id0, grp=GRP, rvs=[\"yhat\"], mdlnm=\"mdl0\", ynm=\"y\")"
|
2396 | 2399 | ]
|
2397 | 2400 | },
|
|
2562 | 2565 | }
|
2563 | 2566 | ],
|
2564 | 2567 | "source": [
|
2565 |
| - "GRP = 'posterior'\n", |
| 2568 | + "GRP = \"posterior\"\n", |
2566 | 2569 | "with mdl0:\n",
|
2567 | 2570 | " id0.extend(pm.sample(**SAMPLE_KWS), join=\"right\")\n",
|
2568 | 2571 | " id0.extend(\n",
|
|
2972 | 2975 | " _ = f.tight_layout()\n",
|
2973 | 2976 | " return f\n",
|
2974 | 2977 | "\n",
|
| 2978 | + "\n", |
2975 | 2979 | "f = plot_forest(id0, grp=GRP, rvs=[\"beta_j\"], mdlnm=\"mdl0\")"
|
2976 | 2980 | ]
|
2977 | 2981 | },
|
|
3371 | 3375 | "FTS_XJ = [\"intercept\", \"a\", \"b\"]\n",
|
3372 | 3376 | "FTS_XK = [\"c\", \"d\"]\n",
|
3373 | 3377 | "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", |
3378 | 3382 | "\n",
|
3379 | 3383 | "with pm.Model(coords=COORDS) as mdla:\n",
|
3380 | 3384 | " # 0. create (Mutable)Data containers for obs (Y, X)\n",
|
3381 | 3385 | " y = pm.Data(\"y\", dfx_train[ft_y].values, dims=\"oid\")\n",
|
3382 | 3386 | " xj = pm.Data(\"xj\", dfx_train[FTS_XJ].values, dims=(\"oid\", \"xj_nm\"))\n",
|
3383 | 3387 | "\n",
|
3384 | 3388 | " # 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", |
3386 | 3390 | " # into a pm.Data, so dfx_train[FTS_XK].values has to go in directly\n",
|
3387 | 3391 | " 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", |
3389 | 3395 | "\n",
|
3390 | 3396 | " # 2. define priors for contiguous and auto-imputed data\n",
|
3391 | 3397 | " b_s = pm.Gamma(\"beta_sigma\", alpha=10, beta=10) # E ~ 1\n",
|
|
3709 | 3715 | }
|
3710 | 3716 | ],
|
3711 | 3717 | "source": [
|
3712 |
| - "GRP = 'prior'\n", |
| 3718 | + "GRP = \"prior\"\n", |
3713 | 3719 | "kws = dict(samples=2000, return_inferencedata=True, random_seed=42)\n",
|
3714 | 3720 | "with mdla:\n",
|
3715 | 3721 | " ida = pm.sample_prior_predictive(\n",
|
|
3976 | 3982 | }
|
3977 | 3983 | ],
|
3978 | 3984 | "source": [
|
3979 |
| - "GRP = 'posterior'\n", |
| 3985 | + "GRP = \"posterior\"\n", |
3980 | 3986 | "with mdla:\n",
|
3981 | 3987 | " ida.extend(pm.sample(**SAMPLE_KWS), join=\"right\")\n",
|
3982 | 3988 | " ida.extend(\n",
|
|
5228 | 5234 | "\n",
|
5229 | 5235 | " # same code as above for mdla\n",
|
5230 | 5236 | " # 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", |
5232 | 5238 | " # into a pm.Data, so dfx_holdout[FTS_XK].values has to go in directly\n",
|
5233 | 5239 | " 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", |
5235 | 5243 | "\n",
|
5236 | 5244 | " # 2. define priors for contiguous and auto-imputed data\n",
|
5237 | 5245 | " b_s = pm.Gamma(\"beta_sigma\", alpha=10, beta=10) # E ~ 1\n",
|
|
0 commit comments