From 6e8f02dca10f3c5ca0ec889cbfc02a66a56116c2 Mon Sep 17 00:00:00 2001 From: Allen Downey Date: Sat, 4 Nov 2023 19:49:10 -0400 Subject: [PATCH] Updating the notebooks --- notebooks/chap01.ipynb | 2 +- notebooks/chap12.ipynb | 645 ++++------------------------------------- notebooks/utils.py | 12 +- 3 files changed, 68 insertions(+), 591 deletions(-) diff --git a/notebooks/chap01.ipynb b/notebooks/chap01.ipynb index 7539225c..10c89633 100644 --- a/notebooks/chap01.ipynb +++ b/notebooks/chap01.ipynb @@ -1127,7 +1127,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### The Law of Total Probability\n", + "## The Law of Total Probability\n", "\n", "In addition to these three theorems, there's one more thing we'll need to do Bayesian statistics: the law of total probability.\n", "Here's one form of the law, expressed in mathematical notation:\n", diff --git a/notebooks/chap12.ipynb b/notebooks/chap12.ipynb index 943ac832..01e95f9f 100644 --- a/notebooks/chap12.ipynb +++ b/notebooks/chap12.ipynb @@ -24,12 +24,6 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:18.288138Z", - "iopub.status.busy": "2021-04-16T19:37:18.287692Z", - "iopub.status.idle": "2021-04-16T19:37:18.289835Z", - "shell.execute_reply": "2021-04-16T19:37:18.289416Z" - }, "tags": [] }, "outputs": [], @@ -48,12 +42,6 @@ "cell_type": "code", "execution_count": 2, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:18.293250Z", - "iopub.status.busy": "2021-04-16T19:37:18.292789Z", - "iopub.status.idle": "2021-04-16T19:37:18.294513Z", - "shell.execute_reply": "2021-04-16T19:37:18.294915Z" - }, "tags": [] }, "outputs": [], @@ -76,12 +64,6 @@ "cell_type": "code", "execution_count": 3, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:18.297920Z", - "iopub.status.busy": "2021-04-16T19:37:18.297468Z", - "iopub.status.idle": "2021-04-16T19:37:18.991445Z", - "shell.execute_reply": "2021-04-16T19:37:18.990956Z" - }, "tags": [] }, "outputs": [], @@ -95,12 +77,6 @@ "cell_type": "code", "execution_count": 4, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:18.994654Z", - "iopub.status.busy": "2021-04-16T19:37:18.994183Z", - "iopub.status.idle": "2021-04-16T19:37:18.995880Z", - "shell.execute_reply": "2021-04-16T19:37:18.996227Z" - }, "tags": [] }, "outputs": [], @@ -114,12 +90,6 @@ "cell_type": "code", "execution_count": 5, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.000543Z", - "iopub.status.busy": "2021-04-16T19:37:19.000024Z", - "iopub.status.idle": "2021-04-16T19:37:19.002391Z", - "shell.execute_reply": "2021-04-16T19:37:19.001974Z" - }, "tags": [] }, "outputs": [], @@ -159,12 +129,6 @@ "cell_type": "code", "execution_count": 6, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.006217Z", - "iopub.status.busy": "2021-04-16T19:37:19.005694Z", - "iopub.status.idle": "2021-04-16T19:37:19.007955Z", - "shell.execute_reply": "2021-04-16T19:37:19.007562Z" - }, "tags": [] }, "outputs": [], @@ -173,7 +137,7 @@ "# https://github.com/allisonhorst/palmerpenguins\n", "# With gratitude to Allison Horst (@allison_horst)\n", "\n", - "download('https://github.com/allisonhorst/palmerpenguins/raw/main/inst/extdata/penguins_raw.csv')" + "download('https://github.com/allisonhorst/palmerpenguins/raw/master/inst/extdata/penguins_raw.csv')" ] }, { @@ -188,14 +152,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.011281Z", - "iopub.status.busy": "2021-04-16T19:37:19.010728Z", - "iopub.status.idle": "2021-04-16T19:37:19.044097Z", - "shell.execute_reply": "2021-04-16T19:37:19.044463Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", @@ -215,12 +172,6 @@ "cell_type": "code", "execution_count": 8, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.048415Z", - "iopub.status.busy": "2021-04-16T19:37:19.047976Z", - "iopub.status.idle": "2021-04-16T19:37:19.065696Z", - "shell.execute_reply": "2021-04-16T19:37:19.066074Z" - }, "tags": [] }, "outputs": [], @@ -241,12 +192,6 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.070492Z", - "iopub.status.busy": "2021-04-16T19:37:19.070076Z", - "iopub.status.idle": "2021-04-16T19:37:19.071826Z", - "shell.execute_reply": "2021-04-16T19:37:19.072191Z" - }, "tags": [] }, "outputs": [], @@ -316,14 +261,7 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.075960Z", - "iopub.status.busy": "2021-04-16T19:37:19.075536Z", - "iopub.status.idle": "2021-04-16T19:37:19.077767Z", - "shell.execute_reply": "2021-04-16T19:37:19.077267Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def make_cdf_map(df, colname, by='Species2'):\n", @@ -348,12 +286,6 @@ "cell_type": "code", "execution_count": 11, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.081866Z", - "iopub.status.busy": "2021-04-16T19:37:19.081358Z", - "iopub.status.idle": "2021-04-16T19:37:19.082993Z", - "shell.execute_reply": "2021-04-16T19:37:19.083335Z" - }, "tags": [] }, "outputs": [], @@ -390,12 +322,6 @@ "cell_type": "code", "execution_count": 12, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.088740Z", - "iopub.status.busy": "2021-04-16T19:37:19.088145Z", - "iopub.status.idle": "2021-04-16T19:37:19.303168Z", - "shell.execute_reply": "2021-04-16T19:37:19.302435Z" - }, "tags": [] }, "outputs": [], @@ -417,12 +343,6 @@ "cell_type": "code", "execution_count": 13, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.331398Z", - "iopub.status.busy": "2021-04-16T19:37:19.308397Z", - "iopub.status.idle": "2021-04-16T19:37:19.517982Z", - "shell.execute_reply": "2021-04-16T19:37:19.518346Z" - }, "tags": [] }, "outputs": [], @@ -453,12 +373,6 @@ "cell_type": "code", "execution_count": 14, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.524204Z", - "iopub.status.busy": "2021-04-16T19:37:19.521721Z", - "iopub.status.idle": "2021-04-16T19:37:19.703780Z", - "shell.execute_reply": "2021-04-16T19:37:19.703345Z" - }, "tags": [] }, "outputs": [], @@ -480,12 +394,6 @@ "cell_type": "code", "execution_count": 15, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.729774Z", - "iopub.status.busy": "2021-04-16T19:37:19.707634Z", - "iopub.status.idle": "2021-04-16T19:37:19.907033Z", - "shell.execute_reply": "2021-04-16T19:37:19.906567Z" - }, "tags": [] }, "outputs": [], @@ -527,14 +435,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.911218Z", - "iopub.status.busy": "2021-04-16T19:37:19.910745Z", - "iopub.status.idle": "2021-04-16T19:37:19.912386Z", - "shell.execute_reply": "2021-04-16T19:37:19.912766Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from scipy.stats import norm\n", @@ -560,14 +461,7 @@ { "cell_type": "code", "execution_count": 17, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.918583Z", - "iopub.status.busy": "2021-04-16T19:37:19.915902Z", - "iopub.status.idle": "2021-04-16T19:37:19.922654Z", - "shell.execute_reply": "2021-04-16T19:37:19.923116Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "flipper_map = make_norm_map(df, 'Flipper Length (mm)')\n", @@ -586,14 +480,7 @@ { "cell_type": "code", "execution_count": 18, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.927490Z", - "iopub.status.busy": "2021-04-16T19:37:19.926925Z", - "iopub.status.idle": "2021-04-16T19:37:19.929310Z", - "shell.execute_reply": "2021-04-16T19:37:19.929816Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "data = 193\n", @@ -612,14 +499,7 @@ { "cell_type": "code", "execution_count": 19, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.934458Z", - "iopub.status.busy": "2021-04-16T19:37:19.933961Z", - "iopub.status.idle": "2021-04-16T19:37:19.936520Z", - "shell.execute_reply": "2021-04-16T19:37:19.936128Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "hypos = flipper_map.keys()\n", @@ -646,14 +526,7 @@ { "cell_type": "code", "execution_count": 20, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.944063Z", - "iopub.status.busy": "2021-04-16T19:37:19.943376Z", - "iopub.status.idle": "2021-04-16T19:37:19.946269Z", - "shell.execute_reply": "2021-04-16T19:37:19.946617Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from empiricaldist import Pmf\n", @@ -672,14 +545,7 @@ { "cell_type": "code", "execution_count": 21, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.953232Z", - "iopub.status.busy": "2021-04-16T19:37:19.952744Z", - "iopub.status.idle": "2021-04-16T19:37:19.955194Z", - "shell.execute_reply": "2021-04-16T19:37:19.955555Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "posterior = prior * likelihood\n", @@ -700,14 +566,7 @@ { "cell_type": "code", "execution_count": 22, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.960404Z", - "iopub.status.busy": "2021-04-16T19:37:19.959801Z", - "iopub.status.idle": "2021-04-16T19:37:19.962299Z", - "shell.execute_reply": "2021-04-16T19:37:19.961720Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def update_penguin(prior, data, norm_map):\n", @@ -731,14 +590,7 @@ { "cell_type": "code", "execution_count": 23, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.970218Z", - "iopub.status.busy": "2021-04-16T19:37:19.969685Z", - "iopub.status.idle": "2021-04-16T19:37:19.971927Z", - "shell.execute_reply": "2021-04-16T19:37:19.972294Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "posterior1 = update_penguin(prior, 193, flipper_map)\n", @@ -758,14 +610,7 @@ { "cell_type": "code", "execution_count": 24, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.977739Z", - "iopub.status.busy": "2021-04-16T19:37:19.976754Z", - "iopub.status.idle": "2021-04-16T19:37:19.981002Z", - "shell.execute_reply": "2021-04-16T19:37:19.980505Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "culmen_map = make_norm_map(df, 'Culmen Length (mm)')" @@ -782,14 +627,7 @@ { "cell_type": "code", "execution_count": 25, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.988152Z", - "iopub.status.busy": "2021-04-16T19:37:19.987625Z", - "iopub.status.idle": "2021-04-16T19:37:19.990363Z", - "shell.execute_reply": "2021-04-16T19:37:19.989998Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "posterior2 = update_penguin(prior, 48, culmen_map)\n", @@ -818,14 +656,7 @@ { "cell_type": "code", "execution_count": 26, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.994218Z", - "iopub.status.busy": "2021-04-16T19:37:19.993697Z", - "iopub.status.idle": "2021-04-16T19:37:19.995829Z", - "shell.execute_reply": "2021-04-16T19:37:19.995463Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def update_naive(prior, data_seq, norm_maps):\n", @@ -855,14 +686,7 @@ { "cell_type": "code", "execution_count": 27, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:19.999103Z", - "iopub.status.busy": "2021-04-16T19:37:19.998544Z", - "iopub.status.idle": "2021-04-16T19:37:20.000215Z", - "shell.execute_reply": "2021-04-16T19:37:20.000576Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "colnames = ['Flipper Length (mm)', 'Culmen Length (mm)']\n", @@ -880,14 +704,7 @@ { "cell_type": "code", "execution_count": 28, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:20.009075Z", - "iopub.status.busy": "2021-04-16T19:37:20.008454Z", - "iopub.status.idle": "2021-04-16T19:37:20.011330Z", - "shell.execute_reply": "2021-04-16T19:37:20.011754Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "data_seq = 193, 48\n", @@ -905,14 +722,7 @@ { "cell_type": "code", "execution_count": 29, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:20.015770Z", - "iopub.status.busy": "2021-04-16T19:37:20.015173Z", - "iopub.status.idle": "2021-04-16T19:37:20.017887Z", - "shell.execute_reply": "2021-04-16T19:37:20.018251Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "posterior.max_prob()" @@ -928,14 +738,7 @@ { "cell_type": "code", "execution_count": 30, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:20.023491Z", - "iopub.status.busy": "2021-04-16T19:37:20.022789Z", - "iopub.status.idle": "2021-04-16T19:37:20.981981Z", - "shell.execute_reply": "2021-04-16T19:37:20.981550Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", @@ -961,12 +764,6 @@ "cell_type": "code", "execution_count": 31, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:20.985633Z", - "iopub.status.busy": "2021-04-16T19:37:20.984867Z", - "iopub.status.idle": "2021-04-16T19:37:20.987360Z", - "shell.execute_reply": "2021-04-16T19:37:20.987711Z" - }, "tags": [] }, "outputs": [], @@ -977,14 +774,7 @@ { "cell_type": "code", "execution_count": 32, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:20.991610Z", - "iopub.status.busy": "2021-04-16T19:37:20.991151Z", - "iopub.status.idle": "2021-04-16T19:37:20.993953Z", - "shell.execute_reply": "2021-04-16T19:37:20.993589Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "valid = df['Classification'].notna()\n", @@ -994,14 +784,7 @@ { "cell_type": "code", "execution_count": 33, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:20.998143Z", - "iopub.status.busy": "2021-04-16T19:37:20.997582Z", - "iopub.status.idle": "2021-04-16T19:37:20.999968Z", - "shell.execute_reply": "2021-04-16T19:37:21.000342Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "same = df['Species2'] == df['Classification']\n", @@ -1019,14 +802,7 @@ { "cell_type": "code", "execution_count": 34, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.004190Z", - "iopub.status.busy": "2021-04-16T19:37:21.003664Z", - "iopub.status.idle": "2021-04-16T19:37:21.006287Z", - "shell.execute_reply": "2021-04-16T19:37:21.005922Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "same.sum() / valid.sum()" @@ -1042,14 +818,7 @@ { "cell_type": "code", "execution_count": 35, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.009603Z", - "iopub.status.busy": "2021-04-16T19:37:21.009164Z", - "iopub.status.idle": "2021-04-16T19:37:21.010827Z", - "shell.execute_reply": "2021-04-16T19:37:21.011182Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def accuracy(df):\n", @@ -1078,14 +847,7 @@ { "cell_type": "code", "execution_count": 36, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.015102Z", - "iopub.status.busy": "2021-04-16T19:37:21.014619Z", - "iopub.status.idle": "2021-04-16T19:37:21.016514Z", - "shell.execute_reply": "2021-04-16T19:37:21.016973Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", @@ -1095,7 +857,7 @@ " grouped = df.groupby('Species2')\n", " for species, group in grouped:\n", " plt.plot(group[var1], group[var2],\n", - " label=species, lw=0, alpha=0.3)\n", + " label=species, ls=\"None\", alpha=0.3)\n", " \n", " decorate(xlabel=var1, ylabel=var2)" ] @@ -1110,14 +872,7 @@ { "cell_type": "code", "execution_count": 37, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.022398Z", - "iopub.status.busy": "2021-04-16T19:37:21.021391Z", - "iopub.status.idle": "2021-04-16T19:37:21.203851Z", - "shell.execute_reply": "2021-04-16T19:37:21.203425Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "var1 = 'Flipper Length (mm)'\n", @@ -1139,14 +894,7 @@ { "cell_type": "code", "execution_count": 38, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.208040Z", - "iopub.status.busy": "2021-04-16T19:37:21.207520Z", - "iopub.status.idle": "2021-04-16T19:37:21.209803Z", - "shell.execute_reply": "2021-04-16T19:37:21.209356Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def make_pmf_norm(dist, sigmas=3, n=101):\n", @@ -1171,14 +919,7 @@ { "cell_type": "code", "execution_count": 39, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.217204Z", - "iopub.status.busy": "2021-04-16T19:37:21.216308Z", - "iopub.status.idle": "2021-04-16T19:37:21.224243Z", - "shell.execute_reply": "2021-04-16T19:37:21.223791Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from utils import make_joint\n", @@ -1200,14 +941,7 @@ { "cell_type": "code", "execution_count": 40, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.242009Z", - "iopub.status.busy": "2021-04-16T19:37:21.238850Z", - "iopub.status.idle": "2021-04-16T19:37:21.479441Z", - "shell.execute_reply": "2021-04-16T19:37:21.479791Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from utils import plot_contour\n", @@ -1245,14 +979,7 @@ { "cell_type": "code", "execution_count": 41, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.483823Z", - "iopub.status.busy": "2021-04-16T19:37:21.483359Z", - "iopub.status.idle": "2021-04-16T19:37:21.485585Z", - "shell.execute_reply": "2021-04-16T19:37:21.485083Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "features = df[[var1, var2]]" @@ -1268,14 +995,7 @@ { "cell_type": "code", "execution_count": 42, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.490474Z", - "iopub.status.busy": "2021-04-16T19:37:21.489968Z", - "iopub.status.idle": "2021-04-16T19:37:21.492332Z", - "shell.execute_reply": "2021-04-16T19:37:21.492765Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "mean = features.mean()\n", @@ -1292,14 +1012,7 @@ { "cell_type": "code", "execution_count": 43, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.500963Z", - "iopub.status.busy": "2021-04-16T19:37:21.500193Z", - "iopub.status.idle": "2021-04-16T19:37:21.503087Z", - "shell.execute_reply": "2021-04-16T19:37:21.503533Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "cov = features.cov()\n", @@ -1322,14 +1035,7 @@ { "cell_type": "code", "execution_count": 44, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.510841Z", - "iopub.status.busy": "2021-04-16T19:37:21.510344Z", - "iopub.status.idle": "2021-04-16T19:37:21.512378Z", - "shell.execute_reply": "2021-04-16T19:37:21.511992Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from scipy.stats import multivariate_normal\n", @@ -1347,14 +1053,7 @@ { "cell_type": "code", "execution_count": 45, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.516025Z", - "iopub.status.busy": "2021-04-16T19:37:21.515613Z", - "iopub.status.idle": "2021-04-16T19:37:21.517669Z", - "shell.execute_reply": "2021-04-16T19:37:21.517308Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def make_multinorm_map(df, colnames):\n", @@ -1379,14 +1078,7 @@ { "cell_type": "code", "execution_count": 46, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.520704Z", - "iopub.status.busy": "2021-04-16T19:37:21.520278Z", - "iopub.status.idle": "2021-04-16T19:37:21.529601Z", - "shell.execute_reply": "2021-04-16T19:37:21.530111Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "multinorm_map = make_multinorm_map(df, [var1, var2])" @@ -1410,12 +1102,6 @@ "cell_type": "code", "execution_count": 47, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.534127Z", - "iopub.status.busy": "2021-04-16T19:37:21.533630Z", - "iopub.status.idle": "2021-04-16T19:37:21.535670Z", - "shell.execute_reply": "2021-04-16T19:37:21.535312Z" - }, "tags": [] }, "outputs": [], @@ -1438,12 +1124,6 @@ "cell_type": "code", "execution_count": 48, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.540839Z", - "iopub.status.busy": "2021-04-16T19:37:21.540411Z", - "iopub.status.idle": "2021-04-16T19:37:21.542132Z", - "shell.execute_reply": "2021-04-16T19:37:21.542474Z" - }, "tags": [] }, "outputs": [], @@ -1465,12 +1145,6 @@ "cell_type": "code", "execution_count": 49, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.545987Z", - "iopub.status.busy": "2021-04-16T19:37:21.545244Z", - "iopub.status.idle": "2021-04-16T19:37:21.548896Z", - "shell.execute_reply": "2021-04-16T19:37:21.549367Z" - }, "tags": [] }, "outputs": [], @@ -1494,12 +1168,6 @@ "cell_type": "code", "execution_count": 50, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.553038Z", - "iopub.status.busy": "2021-04-16T19:37:21.552338Z", - "iopub.status.idle": "2021-04-16T19:37:21.556566Z", - "shell.execute_reply": "2021-04-16T19:37:21.557009Z" - }, "tags": [] }, "outputs": [], @@ -1521,12 +1189,6 @@ "cell_type": "code", "execution_count": 51, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.560465Z", - "iopub.status.busy": "2021-04-16T19:37:21.559912Z", - "iopub.status.idle": "2021-04-16T19:37:21.566335Z", - "shell.execute_reply": "2021-04-16T19:37:21.565694Z" - }, "tags": [] }, "outputs": [], @@ -1548,12 +1210,6 @@ "cell_type": "code", "execution_count": 52, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.571487Z", - "iopub.status.busy": "2021-04-16T19:37:21.571021Z", - "iopub.status.idle": "2021-04-16T19:37:21.575812Z", - "shell.execute_reply": "2021-04-16T19:37:21.575460Z" - }, "tags": [] }, "outputs": [], @@ -1577,12 +1233,6 @@ "cell_type": "code", "execution_count": 53, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.593523Z", - "iopub.status.busy": "2021-04-16T19:37:21.593043Z", - "iopub.status.idle": "2021-04-16T19:37:21.720706Z", - "shell.execute_reply": "2021-04-16T19:37:21.721051Z" - }, "tags": [] }, "outputs": [], @@ -1607,12 +1257,6 @@ "cell_type": "code", "execution_count": 54, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.725452Z", - "iopub.status.busy": "2021-04-16T19:37:21.725003Z", - "iopub.status.idle": "2021-04-16T19:37:21.728131Z", - "shell.execute_reply": "2021-04-16T19:37:21.727783Z" - }, "tags": [] }, "outputs": [], @@ -1644,12 +1288,6 @@ "cell_type": "code", "execution_count": 55, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.742236Z", - "iopub.status.busy": "2021-04-16T19:37:21.741830Z", - "iopub.status.idle": "2021-04-16T19:37:21.959124Z", - "shell.execute_reply": "2021-04-16T19:37:21.958746Z" - }, "tags": [] }, "outputs": [], @@ -1683,14 +1321,7 @@ { "cell_type": "code", "execution_count": 56, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.962781Z", - "iopub.status.busy": "2021-04-16T19:37:21.962359Z", - "iopub.status.idle": "2021-04-16T19:37:21.964347Z", - "shell.execute_reply": "2021-04-16T19:37:21.963983Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "def update_penguin(prior, data, norm_map):\n", @@ -1714,14 +1345,7 @@ { "cell_type": "code", "execution_count": 57, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.970821Z", - "iopub.status.busy": "2021-04-16T19:37:21.970316Z", - "iopub.status.idle": "2021-04-16T19:37:21.972638Z", - "shell.execute_reply": "2021-04-16T19:37:21.972985Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "data = 193, 48\n", @@ -1741,14 +1365,7 @@ { "cell_type": "code", "execution_count": 58, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:21.994890Z", - "iopub.status.busy": "2021-04-16T19:37:21.976850Z", - "iopub.status.idle": "2021-04-16T19:37:22.492006Z", - "shell.execute_reply": "2021-04-16T19:37:22.491490Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "df['Classification'] = np.nan\n", @@ -1769,14 +1386,7 @@ { "cell_type": "code", "execution_count": 59, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:22.496290Z", - "iopub.status.busy": "2021-04-16T19:37:22.495665Z", - "iopub.status.idle": "2021-04-16T19:37:22.498009Z", - "shell.execute_reply": "2021-04-16T19:37:22.498355Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "accuracy(df)" @@ -1835,14 +1445,7 @@ { "cell_type": "code", "execution_count": 60, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:22.510264Z", - "iopub.status.busy": "2021-04-16T19:37:22.502240Z", - "iopub.status.idle": "2021-04-16T19:37:22.511818Z", - "shell.execute_reply": "2021-04-16T19:37:22.512227Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -1851,14 +1454,7 @@ { "cell_type": "code", "execution_count": 61, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:22.515369Z", - "iopub.status.busy": "2021-04-16T19:37:22.514953Z", - "iopub.status.idle": "2021-04-16T19:37:22.516745Z", - "shell.execute_reply": "2021-04-16T19:37:22.517113Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -1867,14 +1463,7 @@ { "cell_type": "code", "execution_count": 62, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:22.521294Z", - "iopub.status.busy": "2021-04-16T19:37:22.520797Z", - "iopub.status.idle": "2021-04-16T19:37:24.132111Z", - "shell.execute_reply": "2021-04-16T19:37:24.131589Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -1902,12 +1491,6 @@ "cell_type": "code", "execution_count": 63, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.136450Z", - "iopub.status.busy": "2021-04-16T19:37:24.136012Z", - "iopub.status.idle": "2021-04-16T19:37:24.138313Z", - "shell.execute_reply": "2021-04-16T19:37:24.137929Z" - }, "tags": [] }, "outputs": [], @@ -1920,12 +1503,6 @@ "cell_type": "code", "execution_count": 64, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.143347Z", - "iopub.status.busy": "2021-04-16T19:37:24.142770Z", - "iopub.status.idle": "2021-04-16T19:37:24.145149Z", - "shell.execute_reply": "2021-04-16T19:37:24.145516Z" - }, "tags": [] }, "outputs": [], @@ -1937,12 +1514,6 @@ "cell_type": "code", "execution_count": 65, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.149670Z", - "iopub.status.busy": "2021-04-16T19:37:24.149059Z", - "iopub.status.idle": "2021-04-16T19:37:24.151974Z", - "shell.execute_reply": "2021-04-16T19:37:24.151609Z" - }, "tags": [] }, "outputs": [], @@ -1955,12 +1526,6 @@ "cell_type": "code", "execution_count": 66, "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.155918Z", - "iopub.status.busy": "2021-04-16T19:37:24.155414Z", - "iopub.status.idle": "2021-04-16T19:37:24.157757Z", - "shell.execute_reply": "2021-04-16T19:37:24.157299Z" - }, "tags": [] }, "outputs": [], @@ -1980,14 +1545,7 @@ { "cell_type": "code", "execution_count": 67, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.183443Z", - "iopub.status.busy": "2021-04-16T19:37:24.162804Z", - "iopub.status.idle": "2021-04-16T19:37:24.350616Z", - "shell.execute_reply": "2021-04-16T19:37:24.350965Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -1996,14 +1554,7 @@ { "cell_type": "code", "execution_count": 68, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.380991Z", - "iopub.status.busy": "2021-04-16T19:37:24.380355Z", - "iopub.status.idle": "2021-04-16T19:37:24.513043Z", - "shell.execute_reply": "2021-04-16T19:37:24.512695Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2012,14 +1563,7 @@ { "cell_type": "code", "execution_count": 69, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.616223Z", - "iopub.status.busy": "2021-04-16T19:37:24.593373Z", - "iopub.status.idle": "2021-04-16T19:37:24.723355Z", - "shell.execute_reply": "2021-04-16T19:37:24.723837Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2028,14 +1572,7 @@ { "cell_type": "code", "execution_count": 70, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.744233Z", - "iopub.status.busy": "2021-04-16T19:37:24.743536Z", - "iopub.status.idle": "2021-04-16T19:37:24.870390Z", - "shell.execute_reply": "2021-04-16T19:37:24.870886Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2044,14 +1581,7 @@ { "cell_type": "code", "execution_count": 71, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.884204Z", - "iopub.status.busy": "2021-04-16T19:37:24.883682Z", - "iopub.status.idle": "2021-04-16T19:37:24.886012Z", - "shell.execute_reply": "2021-04-16T19:37:24.885502Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2060,14 +1590,7 @@ { "cell_type": "code", "execution_count": 72, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.889220Z", - "iopub.status.busy": "2021-04-16T19:37:24.888769Z", - "iopub.status.idle": "2021-04-16T19:37:24.892007Z", - "shell.execute_reply": "2021-04-16T19:37:24.891596Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2076,14 +1599,7 @@ { "cell_type": "code", "execution_count": 73, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:24.897922Z", - "iopub.status.busy": "2021-04-16T19:37:24.897502Z", - "iopub.status.idle": "2021-04-16T19:37:24.901421Z", - "shell.execute_reply": "2021-04-16T19:37:24.900935Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2092,14 +1608,7 @@ { "cell_type": "code", "execution_count": 74, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:25.474486Z", - "iopub.status.busy": "2021-04-16T19:37:25.455002Z", - "iopub.status.idle": "2021-04-16T19:37:25.476802Z", - "shell.execute_reply": "2021-04-16T19:37:25.476362Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2108,14 +1617,7 @@ { "cell_type": "code", "execution_count": 75, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:25.480415Z", - "iopub.status.busy": "2021-04-16T19:37:25.479934Z", - "iopub.status.idle": "2021-04-16T19:37:25.481560Z", - "shell.execute_reply": "2021-04-16T19:37:25.481900Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2124,14 +1626,7 @@ { "cell_type": "code", "execution_count": 76, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:25.486192Z", - "iopub.status.busy": "2021-04-16T19:37:25.485498Z", - "iopub.status.idle": "2021-04-16T19:37:25.488708Z", - "shell.execute_reply": "2021-04-16T19:37:25.488247Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2140,14 +1635,7 @@ { "cell_type": "code", "execution_count": 77, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:25.494810Z", - "iopub.status.busy": "2021-04-16T19:37:25.493982Z", - "iopub.status.idle": "2021-04-16T19:37:25.495920Z", - "shell.execute_reply": "2021-04-16T19:37:25.496360Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2156,14 +1644,7 @@ { "cell_type": "code", "execution_count": 78, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:25.542917Z", - "iopub.status.busy": "2021-04-16T19:37:25.511258Z", - "iopub.status.idle": "2021-04-16T19:37:26.220359Z", - "shell.execute_reply": "2021-04-16T19:37:26.220725Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2172,14 +1653,7 @@ { "cell_type": "code", "execution_count": 79, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:26.572075Z", - "iopub.status.busy": "2021-04-16T19:37:26.571436Z", - "iopub.status.idle": "2021-04-16T19:37:26.575569Z", - "shell.execute_reply": "2021-04-16T19:37:26.574618Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2188,14 +1662,7 @@ { "cell_type": "code", "execution_count": 80, - "metadata": { - "execution": { - "iopub.execute_input": "2021-04-16T19:37:26.581437Z", - "iopub.status.busy": "2021-04-16T19:37:26.579982Z", - "iopub.status.idle": "2021-04-16T19:37:26.586297Z", - "shell.execute_reply": "2021-04-16T19:37:26.585917Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "# Solution goes here" @@ -2226,7 +1693,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/notebooks/utils.py b/notebooks/utils.py index 79fe418e..755ac3ad 100644 --- a/notebooks/utils.py +++ b/notebooks/utils.py @@ -1,3 +1,4 @@ +import warnings import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -63,6 +64,14 @@ def underride(d, **options): return d +class SuppressWarning: + def __enter__(self): + warnings.filterwarnings("ignore", category=UserWarning, module="matplotlib") + + def __exit__(self, exc_type, exc_value, traceback): + warnings.filterwarnings("default", category=UserWarning, module="matplotlib") + + def decorate(**options): """Decorate the current axes. @@ -81,7 +90,8 @@ def decorate(**options): if handles: ax.legend(handles, labels) - plt.tight_layout() + with SuppressWarning(): + plt.tight_layout() def savefig(root, **options):