mirror of
https://github.com/ArthurDanjou/handson-ml3.git
synced 2026-01-31 12:07:49 +01:00
Make font sizes consistent across notebooks
This commit is contained in:
@@ -86,11 +86,13 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import matplotlib as mpl\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
"mpl.rc('font', size=12)\n",
|
||||
"mpl.rc('axes', labelsize=14, titlesize=14)\n",
|
||||
"mpl.rc('legend', fontsize=14)"
|
||||
"plt.rc('font', size=14)\n",
|
||||
"plt.rc('axes', labelsize=14, titlesize=14)\n",
|
||||
"plt.rc('legend', fontsize=14)\n",
|
||||
"plt.rc('xtick',labelsize=10)\n",
|
||||
"plt.rc('ytick',labelsize=10)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -136,7 +138,7 @@
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Let's generate a small 3D dataset:"
|
||||
"Let's generate a small 3D dataset. It's an oval shape, rotated in 3D space, with points distributed unevenly, and with quite a lot of noise:"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -145,19 +147,19 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# not in the book – we've generated plenty of datasets before with similar code\n",
|
||||
"# not in the book\n",
|
||||
"\n",
|
||||
"import numpy as np\n",
|
||||
"from scipy.spatial.transform import Rotation\n",
|
||||
"\n",
|
||||
"np.random.seed(42)\n",
|
||||
"m = 60\n",
|
||||
"angles = (np.random.rand(m) ** 3 + 0.5) * 2 * np.pi\n",
|
||||
"X = np.zeros((m, 3))\n",
|
||||
"X[:, 0] = np.cos(angles)\n",
|
||||
"X[:, 1] = np.sin(angles) * 0.5\n",
|
||||
"X += 0.28 * np.random.randn(m, 3)\n",
|
||||
"X = rotate_3d(X, -np.pi / 4, np.pi / 30, -np.pi / 20)\n",
|
||||
"X += [0.2, 0, 0.2]"
|
||||
"X = np.zeros((m, 3)) # initialize 3D dataset\n",
|
||||
"np.random.seed(42)\n",
|
||||
"angles = (np.random.rand(m) ** 3 + 0.5) * 2 * np.pi # uneven distribution\n",
|
||||
"X[:, 0], X[:, 1] = np.cos(angles), np.sin(angles) * 0.5 # oval\n",
|
||||
"X += 0.28 * np.random.randn(m, 3) # add more noise\n",
|
||||
"X = Rotation.from_rotvec([np.pi / 29, -np.pi / 20, np.pi / 4]).apply(X)\n",
|
||||
"X += [0.2, 0, 0.2] # shift a bit"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -435,10 +437,8 @@
|
||||
" length_includes_head=True, head_length=0.1, fc=\"b\", ec=\"b\", zorder=10)\n",
|
||||
"plt.arrow(0, 0, u3[0], u3[1], head_width=0.1, linewidth=1, alpha=0.9,\n",
|
||||
" length_includes_head=True, head_length=0.1, fc=\"b\", ec=\"b\", zorder=10)\n",
|
||||
"plt.text(u1[0] + 0.1, u1[1] - 0.05, r\"$\\mathbf{c_1}$\",\n",
|
||||
" color=\"blue\", fontsize=14)\n",
|
||||
"plt.text(u3[0] + 0.1, u3[1], r\"$\\mathbf{c_2}$\",\n",
|
||||
" color=\"blue\", fontsize=14)\n",
|
||||
"plt.text(u1[0] + 0.1, u1[1] - 0.05, r\"$\\mathbf{c_1}$\", color=\"blue\")\n",
|
||||
"plt.text(u3[0] + 0.1, u3[1], r\"$\\mathbf{c_2}$\", color=\"blue\")\n",
|
||||
"plt.xlabel(\"$x_1$\")\n",
|
||||
"plt.ylabel(\"$x_2$\", rotation=0)\n",
|
||||
"plt.axis([-1.4, 1.4, -1.4, 1.4])\n",
|
||||
@@ -1029,7 +1029,6 @@
|
||||
"source": [
|
||||
"# not in the book – this cell generates and saves Figure 8–10\n",
|
||||
"\n",
|
||||
"plt.title(\"Unrolled swiss roll using LLE\")\n",
|
||||
"plt.scatter(X_unrolled[:, 0], X_unrolled[:, 1],\n",
|
||||
" c=t, cmap=darker_hot)\n",
|
||||
"plt.xlabel(\"$z_1$\")\n",
|
||||
@@ -1038,6 +1037,7 @@
|
||||
"plt.grid(True)\n",
|
||||
"\n",
|
||||
"save_fig(\"lle_unrolling_plot\")\n",
|
||||
"plt.title(\"Unrolled swiss roll using LLE\")\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
@@ -1826,7 +1826,7 @@
|
||||
"\n",
|
||||
"lda = LinearDiscriminantAnalysis(n_components=2)\n",
|
||||
"%time X_lda_reduced = lda.fit_transform(X_sample, y_sample)\n",
|
||||
"plot_digits(X_lda_reduced, y_sample, figsize=(12,12))\n",
|
||||
"plot_digits(X_lda_reduced, y_sample, figsize=(12, 12))\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user