Skip to content

Commit 6363ca2

Browse files
zhai_proamueller
authored andcommitted
TST: add a test for fortran-aligned data be used in KMeans.
1 parent 86273fd commit 6363ca2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sklearn/cluster/tests/test_k_means.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,18 @@ def test_k_means_n_init():
261261
assert_raises_regexp(ValueError, "n_init", KMeans(n_init=-1).fit, X)
262262

263263

264+
def test_k_means_fortran_aligned_data():
265+
# Check the KMeans will work well, even if X is a fortran-aligned data.
266+
X = np.asfortranarray([[0, 0], [0, 1], [0, 1]])
267+
centers = np.array([[0, 0], [0, 1]])
268+
labels = np.array([0, 1, 1])
269+
km = KMeans(n_init=1, init=centers, precompute_distances=False,
270+
random_state=42)
271+
km.fit(X)
272+
assert_array_equal(km.cluster_centers_, centers)
273+
assert_array_equal(km.labels_, labels)
274+
275+
264276
def test_mb_k_means_plus_plus_init_dense_array():
265277
mb_k_means = MiniBatchKMeans(init="k-means++", n_clusters=n_clusters,
266278
random_state=42)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy