8000 MNT Accelerate_examples plot_digits_linkage.py (#21737) · thomasjpfan/scikit-learn@84c655c · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 84c655c

Browse files
authored
MNT Accelerate_examples plot_digits_linkage.py (scikit-learn#21737)
1 parent bacc91c commit 84c655c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/cluster/plot_digits_linkage.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
from sklearn import manifold, datasets
3939

40-
X, y = datasets.load_digits(return_X_y=True)
40+
digits = datasets.load_digits()
41+
X, y = digits.data, digits.target
4142
n_samples, n_features = X.shape
4243

4344
np.random.seed(0)
@@ -50,13 +51,13 @@ def plot_clustering(X_red, labels, title=None):
5051
X_red = (X_red - x_min) / (x_max - x_min)
5152

5253
plt.figure(figsize=(6, 4))
53-
for i in range(X_red.shape[0]):
54-
plt.text(
55-
X_red[i, 0],
56-
X_red[i, 1],
57-
str(y[i]),
58-
color=plt.cm.nipy_spectral(labels[i] / 10.0),
59-
fontdict={"weight": "bold", "size": 9},
54+
for digit in digits.target_names:
55+
plt.scatter(
56+
*X_red[y == digit].T,
57+
marker=f"${digit}$",
58+
s=50,
59+
c=plt.cm.nipy_spectral(labels[y == digit] / 10),
60+
alpha=0.5,
6061
)
6162

6263
plt.xticks([])

0 commit comments

Comments
 (0)
0