From cfebb4c6554963a30e014cf8264f66b465b93c9b Mon Sep 17 00:00:00 2001 From: Paul Parker Date: Sat, 24 Jan 2026 11:47:51 -0800 Subject: [PATCH 1/3] Fix legend label --- lecturebook/lecture04/reading-04.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lecturebook/lecture04/reading-04.ipynb b/lecturebook/lecture04/reading-04.ipynb index 9846608..250e44e 100644 --- a/lecturebook/lecture04/reading-04.ipynb +++ b/lecturebook/lecture04/reading-04.ipynb @@ -4815,7 +4815,7 @@ "output_type": "display_data" } ], - "source": "# Plot the pdf of a mixture of two normal random variables with different means but the same variance\nfrom scipy.stats import norm\nx = np.linspace(-10, 10, 200)\ny = 0.5 * norm.pdf(x, loc=-5) + 0.5 * norm.pdf(x, loc=5)\nplt.plot(x, y)\n# Add the expected value\nplt.axvline(x=0, color='r', linestyle='--', label='$\\mathbb{E}[X]$')\nplt.xlabel('$x$')\nplt.ylabel('$f_X(x)$')\nsns.despine(trim=True)\nplt.title(\"Example of a case in which the expected value is not representative of the distribution\");" + "source": "# Plot the pdf of a mixture of two normal random variables with different means but the same variance\nfrom scipy.stats import norm\nx = np.linspace(-10, 10, 200)\ny = 0.5 * norm.pdf(x, loc=-5) + 0.5 * norm.pdf(x, loc=5)\nplt.plot(x, y)\n# Add the expected value\nplt.axvline(x=0, color='r', linestyle='--', label=r'$\\mathbb{E}[X]$')\nplt.legend()\nplt.xlabel('$x$')\nplt.ylabel('$f_X(x)$')\nsns.despine(trim=True)\nplt.title(\"Example of a case in which the expected value is not representative of the distribution\");" }, { "cell_type": "markdown", From e0c3b76eb5d0f0b74265fbaf2e51eff24bbd2b02 Mon Sep 17 00:00:00 2001 From: Paul Parker Date: Sat, 24 Jan 2026 11:54:53 -0800 Subject: [PATCH 2/3] Remove warning text --- lecturebook/lecture04/reading-04.ipynb | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/lecturebook/lecture04/reading-04.ipynb b/lecturebook/lecture04/reading-04.ipynb index 250e44e..0563d78 100644 --- a/lecturebook/lecture04/reading-04.ipynb +++ b/lecturebook/lecture04/reading-04.ipynb @@ -3481,19 +3481,12 @@ "iopub.status.busy": "2025-06-16T15:03:23.011568Z", "iopub.status.idle": "2025-06-16T15:03:23.125520Z", "shell.execute_reply": "2025-06-16T15:03:23.125261Z" - } + }, + "tags": [ + "hide-input" + ] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "<>:7: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:7: SyntaxWarning: invalid escape sequence '\\m'\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68920/3227439545.py:7: SyntaxWarning: invalid escape sequence '\\m'\n", - " plt.axvline(x=0, color='r', linestyle='--', label='$\\mathbb{E}[X]$')\n" - ] - }, { "data": { "image/svg+xml": [ From c3167e7a490b38754eb6f08f4047a5dfcf62efec Mon Sep 17 00:00:00 2001 From: Paul Parker Date: Sat, 24 Jan 2026 14:56:12 -0800 Subject: [PATCH 3/3] Fix warnings --- lecturebook/lecture04/hands-on-04.2.ipynb | 76 ++--------------------- 1 file changed, 5 insertions(+), 71 deletions(-) diff --git a/lecturebook/lecture04/hands-on-04.2.ipynb b/lecturebook/lecture04/hands-on-04.2.ipynb index 7051891..b3ce617 100644 --- a/lecturebook/lecture04/hands-on-04.2.ipynb +++ b/lecturebook/lecture04/hands-on-04.2.ipynb @@ -83,16 +83,6 @@ ] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "<>:6: SyntaxWarning: invalid escape sequence '\\p'\n", - "<>:6: SyntaxWarning: invalid escape sequence '\\p'\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/2154087378.py:6: SyntaxWarning: invalid escape sequence '\\p'\n", - " ax.set_ylabel(\"$\\phi(z)$\")\n" - ] - }, { "data": { "image/svg+xml": [ @@ -727,7 +717,7 @@ "output_type": "display_data" } ], - "source": "fig, ax = plt.subplots()\nimport numpy as np\nzs = np.linspace(-4.0, 4.0, 100)\nax.plot(zs, Z.pdf(zs))\nax.set_xlabel(\"$z$\")\nax.set_ylabel(\"$\\phi(z)$\")\nsns.despine(trim=True);" + "source": "fig, ax = plt.subplots()\nimport numpy as np\nzs = np.linspace(-4.0, 4.0, 100)\nax.plot(zs, Z.pdf(zs))\nax.set_xlabel(\"$z$\")\nax.set_ylabel(r\"$\\phi(z)$\")\nsns.despine(trim=True);" }, { "cell_type": "markdown", @@ -749,16 +739,6 @@ ] }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "<>:4: SyntaxWarning: invalid escape sequence '\\P'\n", - "<>:4: SyntaxWarning: invalid escape sequence '\\P'\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/625513495.py:4: SyntaxWarning: invalid escape sequence '\\P'\n", - " ax.set_ylabel(\"$\\Phi(z)$\")\n" - ] - }, { "data": { "image/svg+xml": [ @@ -1396,7 +1376,7 @@ "output_type": "display_data" } ], - "source": "fig, ax = plt.subplots()\nax.plot(zs, Z.cdf(zs))\nax.set_xlabel(\"$z$\")\nax.set_ylabel(\"$\\Phi(z)$\")\nsns.despine(trim=True);" + "source": "fig, ax = plt.subplots()\nax.plot(zs, Z.cdf(zs))\nax.set_xlabel(\"$z$\")\nax.set_ylabel(r\"$\\Phi(z)$\")\nsns.despine(trim=True);" }, { "cell_type": "markdown", @@ -1600,24 +1580,6 @@ } }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "<>:5: SyntaxWarning: invalid escape sequence '\\p'\n", - "<>:6: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:8: SyntaxWarning: invalid escape sequence '\\p'\n", - "<>:5: SyntaxWarning: invalid escape sequence '\\p'\n", - "<>:6: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:8: SyntaxWarning: invalid escape sequence '\\p'\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/2312143129.py:5: SyntaxWarning: invalid escape sequence '\\p'\n", - " ax.plot(zs, Z.pdf(zs), label=\"$\\phi(x)$\")\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/2312143129.py:6: SyntaxWarning: invalid escape sequence '\\m'\n", - " ax.plot(zs, st.norm(loc=1.0).pdf(zs), label=\"$N(x|\\mu=1,\\sigma^2=1)$\")\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/2312143129.py:8: SyntaxWarning: invalid escape sequence '\\p'\n", - " ax.set_ylabel(\"$\\phi(x)$\")\n" - ] - }, { "data": { "image/svg+xml": [ @@ -2997,7 +2959,7 @@ "output_type": "display_data" } ], - "source": "# Plot the PDF of a standard normal and the PDF of a non-zero mean, unit variance normal\n# with an arrow indicating the change from the first to the second.\nfig, ax = plt.subplots()\nzs = np.linspace(-4.0, 4.0, 100)\nax.plot(zs, Z.pdf(zs), label=\"$\\phi(x)$\")\nax.plot(zs, st.norm(loc=1.0).pdf(zs), label=\"$N(x|\\mu=1,\\sigma^2=1)$\")\nax.set_xlabel(\"$x$\")\nax.set_ylabel(\"$\\phi(x)$\")\nax.legend(loc=\"best\", frameon=False)\nax.annotate(\"\", xytext=(0.0, 0.4), xy=(1.0, 0.4), arrowprops=dict(arrowstyle=\"->\",\n color=sns.color_palette()[2],\n lw=2))\nplt.title(\"The mean translates the standard normal PDF\")\nsns.despine(trim=True);\n" + "source": "# Plot the PDF of a standard normal and the PDF of a non-zero mean, unit variance normal\n# with an arrow indicating the change from the first to the second.\nfig, ax = plt.subplots()\nzs = np.linspace(-4.0, 4.0, 100)\nax.plot(zs, Z.pdf(zs), label=r\"$\\phi(x)$\")\nax.plot(zs, st.norm(loc=1.0).pdf(zs), label=r\"$N(x|\\mu=1,\\sigma^2=1)$\")\nax.set_xlabel(\"$x$\")\nax.set_ylabel(r\"$\\phi(x)$\")\nax.legend(loc=\"best\", frameon=False)\nax.annotate(\"\", xytext=(0.0, 0.4), xy=(1.0, 0.4), arrowprops=dict(arrowstyle=\"->\",\n color=sns.color_palette()[2],\n lw=2))\nplt.title(\"The mean translates the standard normal PDF\")\nsns.despine(trim=True);\n" }, { "cell_type": "markdown", @@ -3016,20 +2978,6 @@ } }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "<>:4: SyntaxWarning: invalid escape sequence '\\p'\n", - "<>:5: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:4: SyntaxWarning: invalid escape sequence '\\p'\n", - "<>:5: SyntaxWarning: invalid escape sequence '\\m'\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/775679383.py:4: SyntaxWarning: invalid escape sequence '\\p'\n", - " ax.plot(zs, Z.pdf(zs), label=\"$\\phi(x)$\")\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/775679383.py:5: SyntaxWarning: invalid escape sequence '\\m'\n", - " ax.plot(zs, st.norm(loc=0.0, scale=np.sqrt(2.0)).pdf(zs), label=\"$N(x|\\mu=0,\\sigma^2=2)$\")\n" - ] - }, { "data": { "image/svg+xml": [ @@ -4504,7 +4452,7 @@ "output_type": "display_data" } ], - "source": "# Plot the PDF of a standard normal and the pdf of a zero mean Normal with variance two\nfig, ax = plt.subplots()\nzs = np.linspace(-4.0, 4.0, 100)\nax.plot(zs, Z.pdf(zs), label=\"$\\phi(x)$\")\nax.plot(zs, st.norm(loc=0.0, scale=np.sqrt(2.0)).pdf(zs), label=\"$N(x|\\mu=0,\\sigma^2=2)$\")\nax.set_xlabel(\"$x$\")\nax.set_ylabel(\"$p(x)$\")\nax.legend(loc=\"best\", frameon=False)\nplt.title(\"The variance scales the standard normal PDF\")\nsns.despine(trim=True);" + "source": "# Plot the PDF of a standard normal and the pdf of a zero mean Normal with variance two\nfig, ax = plt.subplots()\nzs = np.linspace(-4.0, 4.0, 100)\nax.plot(zs, Z.pdf(zs), label=r\"$\\phi(x)$\")\nax.plot(zs, st.norm(loc=0.0, scale=np.sqrt(2.0)).pdf(zs), label=r\"$N(x|\\mu=0,\\sigma^2=2)$\")\nax.set_xlabel(\"$x$\")\nax.set_ylabel(r\"$p(x)$\")\nax.legend(loc=\"best\", frameon=False)\nplt.title(\"The variance scales the standard normal PDF\")\nsns.despine(trim=True);" }, { "cell_type": "markdown", @@ -5521,20 +5469,6 @@ } }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "<>:2: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:3: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:2: SyntaxWarning: invalid escape sequence '\\m'\n", - "<>:3: SyntaxWarning: invalid escape sequence '\\m'\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/1046293625.py:2: SyntaxWarning: invalid escape sequence '\\m'\n", - " ax.hist(x_samples, density=True, alpha=0.5, label=\"Samples from $X = \\mu + \\sigma Z$\")\n", - "/var/folders/3n/r5vj11ss7lzcdl10vfhb_mw00000gs/T/ipykernel_68902/1046293625.py:3: SyntaxWarning: invalid escape sequence '\\m'\n", - " ax.plot(xs, X.pdf(xs), label=\"PDF of $N(\\mu, \\sigma^2)$\")\n" - ] - }, { "data": { "image/svg+xml": [ @@ -6884,7 +6818,7 @@ "output_type": "display_data" } ], - "source": "fig, ax = plt.subplots()\nax.hist(x_samples, density=True, alpha=0.5, label=\"Samples from $X = \\mu + \\sigma Z$\")\nax.plot(xs, X.pdf(xs), label=\"PDF of $N(\\mu, \\sigma^2)$\")\nax.set_xlabel(\"$x$\")\nax.set_ylabel(\"$p(x)$\")\nplt.legend(loc=\"best\", frameon=False)\nsns.despine(trim=True);" + "source": "fig, ax = plt.subplots()\nax.hist(x_samples, density=True, alpha=0.5, label=r\"Samples from $X = \\mu + \\sigma Z$\")\nax.plot(xs, X.pdf(xs), label=r\"PDF of $N(\\mu, \\sigma^2)$\")\nax.set_xlabel(\"$x$\")\nax.set_ylabel(\"$p(x)$\")\nplt.legend(loc=\"best\", frameon=False)\nsns.despine(trim=True);" }, { "cell_type": "markdown",