diff --git a/Notebooks/Chap05/5_1_Least_Squares_Loss.ipynb b/Notebooks/Chap05/5_1_Least_Squares_Loss.ipynb index 890ce40..74cd44d 100644 --- a/Notebooks/Chap05/5_1_Least_Squares_Loss.ipynb +++ b/Notebooks/Chap05/5_1_Least_Squares_Loss.ipynb @@ -4,7 +4,6 @@ "metadata": { "colab": { "provenance": [], - "authorship_tag": "ABX9TyOJeBMhN9fXO8UepZ4+Pbg6", "include_colab_link": true }, "kernelspec": { @@ -433,12 +432,25 @@ "cell_type": "code", "source": [ "# Now let's plot the likelihood, negative log likelihood, and least squares as a function the value of the offset beta1\n", - "fig, ax = plt.subplots(1,3)\n", - "fig.set_size_inches(10.5, 3.5)\n", - "fig.tight_layout(pad=3.0)\n", - "ax[0].plot(beta_1_vals, likelihoods); ax[0].set_xlabel('beta_1[0]$'); ax[0].set_ylabel('likelihood')\n", - "ax[1].plot(beta_1_vals, nlls); ax[1].set_xlabel('beta_1[0]'); ax[1].set_ylabel('negative log likelihood')\n", - "ax[2].plot(beta_1_vals, sum_squares); ax[2].set_xlabel('beta_1[0]'); ax[2].set_ylabel('sum of squares')\n", + "fig, ax = plt.subplots(1,2)\n", + "fig.set_size_inches(10.5, 5.5)\n", + "fig.tight_layout(pad=10.0)\n", + "likelihood_color = 'tab:red'\n", + "nll_color = 'tab:blue'\n", + "\n", + "ax[0].set_xlabel('beta_1[0, 0]')\n", + "ax[0].set_ylabel('likelihood', color = likelihood_color)\n", + "ax[0].plot(beta_1_vals, likelihoods, color = likelihood_color)\n", + "ax[0].tick_params(axis='y', labelcolor=likelihood_color)\n", + "\n", + "ax00 = ax[0].twinx()\n", + "ax00.plot(beta_1_vals, nlls, color = nll_color)\n", + "ax00.set_ylabel('negative log likelihood', color = nll_color)\n", + "ax00.tick_params(axis='y', labelcolor = nll_color)\n", + "\n", + "plt.axvline(x = beta_1_vals[np.argmax(likelihoods)], linestyle='dotted')\n", + "\n", + "ax[1].plot(beta_1_vals, sum_squares); ax[1].set_xlabel('beta_1[0]'); ax[1].set_ylabel('sum of squares')\n", "plt.show()" ], "metadata": { @@ -519,12 +531,26 @@ "cell_type": "code", "source": [ "# Now let's plot the likelihood, negative log likelihood, and least squares as a function the value of the standard divation sigma\n", - "fig, ax = plt.subplots(1,3)\n", - "fig.set_size_inches(10.5, 3.5)\n", - "fig.tight_layout(pad=3.0)\n", - "ax[0].plot(sigma_vals, likelihoods); ax[0].set_xlabel('$\\sigma$'); ax[0].set_ylabel('likelihood')\n", - "ax[1].plot(sigma_vals, nlls); ax[1].set_xlabel('$\\sigma$'); ax[1].set_ylabel('negative log likelihood')\n", - "ax[2].plot(sigma_vals, sum_squares); ax[2].set_xlabel('$\\sigma$'); ax[2].set_ylabel('sum of squares')\n", + "fig, ax = plt.subplots(1,2)\n", + "fig.set_size_inches(10.5, 5.5)\n", + "fig.tight_layout(pad=10.0)\n", + "likelihood_color = 'tab:red'\n", + "nll_color = 'tab:blue'\n", + "\n", + "\n", + "ax[0].set_xlabel('sigma')\n", + "ax[0].set_ylabel('likelihood', color = likelihood_color)\n", + "ax[0].plot(sigma_vals, likelihoods, color = likelihood_color)\n", + "ax[0].tick_params(axis='y', labelcolor=likelihood_color)\n", + "\n", + "ax00 = ax[0].twinx()\n", + "ax00.plot(sigma_vals, nlls, color = nll_color)\n", + "ax00.set_ylabel('negative log likelihood', color = nll_color)\n", + "ax00.tick_params(axis='y', labelcolor = nll_color)\n", + "\n", + "plt.axvline(x = sigma_vals[np.argmax(likelihoods)], linestyle='dotted')\n", + "\n", + "ax[1].plot(sigma_vals, sum_squares); ax[1].set_xlabel('sigma'); ax[1].set_ylabel('sum of squares')\n", "plt.show()" ], "metadata": { @@ -564,4 +590,4 @@ } } ] -} +} \ No newline at end of file