|
60 | 60 | "source": [ |
61 | 61 | "from skrub import TableReport\n", |
62 | 62 | "\n", |
63 | | - "TableReport(X)" |
| 63 | + "TableReport(X, verbose=0)" |
64 | 64 | ] |
65 | 65 | }, |
66 | 66 | { |
|
171 | 171 | "source": [ |
172 | 172 | "pipe_90 = make_pipeline(StandardScaler(), PCA(n_components=0.90))\n", |
173 | 173 | "pipe_90.fit(X)\n", |
174 | | - "print(f\"n_components_ for 90% threshold: {pipe_90.named_steps['pca'].n_components_}\")" |
| 174 | + "print(\n", |
| 175 | + " f\"n_components_ for 90% threshold: {pipe_90.named_steps['pca'].n_components_}\"\n", |
| 176 | + ")" |
175 | 177 | ] |
176 | 178 | }, |
177 | 179 | { |
|
204 | 206 | " X_split, _ = train_test_split(X, train_size=0.5, random_state=random_state)\n", |
205 | 207 | " pipe_split = make_pipeline(StandardScaler(), PCA())\n", |
206 | 208 | " pipe_split.fit(X_split)\n", |
207 | | - " split_explained.append(pipe_split.named_steps[\"pca\"].explained_variance_ratio_)" |
| 209 | + " split_explained.append(\n", |
| 210 | + " pipe_split.named_steps[\"pca\"].explained_variance_ratio_\n", |
| 211 | + " )" |
208 | 212 | ] |
209 | 213 | }, |
210 | 214 | { |
|
216 | 220 | "fig, ax = plt.subplots(figsize=(8, 4))\n", |
217 | 221 | "\n", |
218 | 222 | "for ev in split_explained:\n", |
219 | | - " ax.plot(np.arange(1, len(ev) + 1), np.cumsum(ev), color=\"tab:blue\", alpha=0.2)\n", |
| 223 | + " ax.plot(\n", |
| 224 | + " np.arange(1, len(ev) + 1), np.cumsum(ev), color=\"tab:blue\", alpha=0.2\n", |
| 225 | + " )\n", |
220 | 226 | "\n", |
221 | | - "ax.plot(components, cumulative, color=\"tab:blue\", linewidth=2, label=\"Full dataset\")\n", |
| 227 | + "ax.plot(\n", |
| 228 | + " components, cumulative, color=\"tab:blue\", linewidth=2, label=\"Full dataset\"\n", |
| 229 | + ")\n", |
222 | 230 | "ax.axhline(0.90, color=\"tab:orange\", linestyle=\"--\", label=\"90%\")\n", |
223 | 231 | "ax.axhline(0.95, color=\"tab:red\", linestyle=\"--\", label=\"95%\")\n", |
224 | 232 | "ax.set_xlabel(\"Number of components\")\n", |
|
318 | 326 | "for ev in split_explained:\n", |
319 | 327 | " ax.plot(np.arange(1, len(ev) + 1), ev, color=\"tab:blue\", alpha=0.2)\n", |
320 | 328 | "\n", |
321 | | - "ax.plot(components, explained, color=\"tab:blue\", linewidth=2, label=\"Full dataset\")\n", |
| 329 | + "ax.plot(\n", |
| 330 | + " components, explained, color=\"tab:blue\", linewidth=2, label=\"Full dataset\"\n", |
| 331 | + ")\n", |
322 | 332 | "ax.axhline(\n", |
323 | 333 | " kaiser_threshold,\n", |
324 | 334 | " color=\"tab:red\",\n", |
|
424 | 434 | "for ax, n_components, label in zip(\n", |
425 | 435 | " axes,\n", |
426 | 436 | " [kaiser_n, threshold_90],\n", |
427 | | - " [f\"Kaiser ({kaiser_n} components)\", f\"90% threshold ({threshold_90} components)\"],\n", |
| 437 | + " [\n", |
| 438 | + " f\"Kaiser ({kaiser_n} components)\",\n", |
| 439 | + " f\"90% threshold ({threshold_90} components)\",\n", |
| 440 | + " ],\n", |
428 | 441 | "):\n", |
429 | 442 | " pipe_km = make_pipeline(\n", |
430 | 443 | " StandardScaler(),\n", |
431 | 444 | " PCA(n_components=n_components),\n", |
432 | 445 | " KMeans(random_state=0),\n", |
433 | 446 | " )\n", |
434 | 447 | " for random_state in range(1, 11):\n", |
435 | | - " X_sub, _ = train_test_split(X, train_size=0.5, random_state=random_state)\n", |
| 448 | + " X_sub, _ = train_test_split(\n", |
| 449 | + " X, train_size=0.5, random_state=random_state\n", |
| 450 | + " )\n", |
436 | 451 | " scores = []\n", |
437 | 452 | " for k in n_clusters_range:\n", |
438 | 453 | " pipe_km[-1].set_params(n_clusters=k)\n", |
|
0 commit comments