Created using Colaboratory

This commit is contained in:
udlbook
2023-12-24 10:16:00 -05:00
parent 48d9a4e108
commit 3cdb675cef

View File

@@ -4,7 +4,7 @@
"metadata": { "metadata": {
"colab": { "colab": {
"provenance": [], "provenance": [],
"authorship_tag": "ABX9TyPNAZtbS+8jYc+tZqhDHNev", "authorship_tag": "ABX9TyOPv/l+ToaApJV7Nz+8AtpV",
"include_colab_link": true "include_colab_link": true
}, },
"kernelspec": { "kernelspec": {
@@ -401,12 +401,25 @@
{ {
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"# Now let's plot the likelihood, negative log likelihood as a function the value of the offset beta1\n", "# 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,2)\n", "fig, ax = plt.subplots()\n",
"fig.set_size_inches(10.5, 3.5)\n", "fig.tight_layout(pad=5.0)\n",
"fig.tight_layout(pad=3.0)\n", "likelihood_color = 'tab:red'\n",
"ax[0].plot(beta_1_vals, likelihoods); ax[0].set_xlabel('beta_1[0,0]'); ax[0].set_ylabel('likelihood')\n", "nll_color = 'tab:blue'\n",
"ax[1].plot(beta_1_vals, nlls); ax[1].set_xlabel('beta_1[0,0]'); ax[1].set_ylabel('negative log likelihood')\n", "\n",
"\n",
"ax.set_xlabel('beta_1[0, 0]')\n",
"ax.set_ylabel('likelihood', color = likelihood_color)\n",
"ax.plot(beta_1_vals, likelihoods, color = likelihood_color)\n",
"ax.tick_params(axis='y', labelcolor=likelihood_color)\n",
"\n",
"ax1 = ax.twinx()\n",
"ax1.plot(beta_1_vals, nlls, color = nll_color)\n",
"ax1.set_ylabel('negative log likelihood', color = nll_color)\n",
"ax1.tick_params(axis='y', labelcolor = nll_color)\n",
"\n",
"plt.axvline(x = beta_1_vals[np.argmax(likelihoods)], linestyle='dotted')\n",
"\n",
"plt.show()" "plt.show()"
], ],
"metadata": { "metadata": {