Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc116ee

Browse filesBrowse files
committed
lint
1 parent a645428 commit fc116ee
Copy full SHA for fc116ee

File tree

1 file changed

+45
-13
lines changed
Filter options

1 file changed

+45
-13
lines changed

‎sklearn/cluster/tests/test_k_means.py

Copy file name to clipboardExpand all lines: sklearn/cluster/tests/test_k_means.py
+45-13Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ def test_kmeans_elkan_results(distribution, array_constr, tol, global_random_see
168168

169169
km_lloyd = KMeans(n_clusters=5, random_state=global_random_seed, n_init=1, tol=tol)
170170
km_elkan = KMeans(
171-
algorithm="elkan", n_clusters=5, random_state=global_random_seed, n_init=1, tol=tol
171+
algorithm="elkan",
172+
n_clusters=5,
173+
random_state=global_random_seed,
174+
n_init=1,
175+
tol=tol,
172176
)
173177

174178
km_lloyd.fit(X)
@@ -333,7 +337,10 @@ def test_fortran_aligned_data(Estimator, global_random_seed):
333337
n_clusters=n_clusters, init=centers, n_init=1, random_state=global_random_seed
334338
).fit(X)
335339
km_f = Estimator(
336-
n_clusters=n_clusters, init=centers_fortran, n_init=1, random_state=global_random_seed
340+
n_clusters=n_clusters,
341+
init=centers_fortran,
342+
n_init=1,
343+
random_state=global_random_seed,
337344
).fit(X_fortran)
338345
assert_allclose(km_c.cluster_centers_, km_f.cluster_centers_)
339346
assert_array_equal(km_c.labels_, km_f.labels_)
@@ -400,7 +407,9 @@ def test_minibatch_sensible_reassign(global_random_seed):
400407
# check that identical initial clusters are reassigned
401408
# also a regression test for when there are more desired reassignments than
402409
# samples.
403-
zeroed_X, true_labels = make_blobs(n_samples=100, centers=5, random_state=global_random_seed)
410+
zeroed_X, true_labels = make_blobs(
411+
n_samples=100, centers=5, random_state=global_random_seed
412+
)
404413
zeroed_X[::2, :] = 0
405414

406415
km = MiniBatchKMeans(
@@ -626,10 +635,16 @@ def test_kmeans_predict(
626635
@pytest.mark.parametrize("Estimator", [KMeans, MiniBatchKMeans])
627636
def test_dense_sparse(Estimator, global_random_seed):
628637
# Check that the results are the same for dense and sparse input.
629-
sample_weight = np.random.RandomState(global_random_seed).random_sample((n_samples,))
630-
km_dense = Estimator(n_clusters=n_clusters, random_state=global_random_seed, n_init=1)
638+
sample_weight = np.random.RandomState(global_random_seed).random_sample(
639+
(n_samples,)
640+
)
641+
km_dense = Estimator(
642+
n_clusters=n_clusters, random_state=global_random_seed, n_init=1
643+
)
631644
km_dense.fit(X, sample_weight=sample_weight)
632-
km_sparse = Estimator(n_clusters=n_clusters, random_state=global_random_seed, n_init=1)
645+
km_sparse = Estimator(
646+
n_clusters=n_clusters, random_state=global_random_seed, n_init=1
647+
)
633648
km_sparse.fit(X_csr, sample_weight=sample_weight)
634649

635650
assert_array_equal(km_dense.labels_, km_sparse.labels_)
@@ -774,7 +789,8 @@ def test_float_precision(Estimator, data, global_random_seed):
774789
assert_allclose(inertia[np.float32], inertia[np.float64], rtol=1e-4)
775790
assert_allclose(Xt[np.float32], Xt[np.float64], atol=Xt[np.float64].max() * 1e-4)
776791
assert_allclose(
777-
centers[np.float32], centers[np.float64], atol=centers[np.float64].max() * 1e-4)
792+
centers[np.float32], centers[np.float64], atol=centers[np.float64].max() * 1e-4
793+
)
778794
assert_array_equal(labels[np.float32], labels[np.float64])
779795

780796

@@ -829,10 +845,14 @@ def test_weighted_vs_repeated(global_random_seed):
829845
# repetition of the sample. Valid only if init is precomputed, otherwise
830846
# rng produces different results. Not valid for MinibatchKMeans due to rng
831847
# to extract minibatches.
832-
sample_weight = np.random.RandomState(global_random_seed).randint(1, 5, size=n_samples)
848+
sample_weight = np.random.RandomState(global_random_seed).randint(
849+
1, 5, size=n_samples
850+
)
833851
X_repeat = np.repeat(X, sample_weight, axis=0)
834852

835-
km = KMeans(init=centers, n_init=1, n_clusters=n_clusters, random_state=global_random_seed)
853+
km = KMeans(
854+
init=centers, n_init=1, n_clusters=n_clusters, random_state=global_random_seed
855+
)
836856

837857
km_weighted = clone(km).fit(X, sample_weight=sample_weight)
838858
repeated_labels = np.repeat(km_weighted.labels_, sample_weight)
@@ -908,9 +928,17 @@ def test_result_equal_in_diff_n_threads(Estimator, global_random_seed):
908928
X = rnd.normal(size=(50, 10))
909929

910930
with threadpool_limits(limits=1, user_api="openmp"):
911-
result_1 = Estimator(n_clusters=n_clusters, random_state=global_random_seed).fit(X).labels_
931+
result_1 = (
932+
Estimator(n_clusters=n_clusters, random_state=global_random_seed)
933+
.fit(X)
934+
.labels_
935+
)
912936
with threadpool_limits(limits=2, user_api="openmp"):
913-
result_2 = Estimator(n_clusters=n_clusters, random_state=global_random_seed).fit(X).labels_
937+
result_2 = (
938+
Estimator(n_clusters=n_clusters, random_state=global_random_seed)
939+
.fit(X)
940+
.labels_
941+
)
914942
assert_array_equal(result_1, result_2)
915943

916944

@@ -1119,7 +1147,9 @@ def test_kmeans_plusplus_wrong_params(param, match):
11191147
def test_kmeans_plusplus_output(data, dtype, global_random_seed):
11201148
# Check for the correct number of seeds and all positive values
11211149
data = data.astype(dtype)
1122-
centers, indices = kmeans_plusplus(data, n_clusters, random_state=global_random_seed)
1150+
centers, indices = kmeans_plusplus(
1151+
data, n_clusters, random_state=global_random_seed
1152+
)
11231153

11241154
# Check there are the correct number of indices and that all indices are
11251155
# positive and within the number of samples
@@ -1152,7 +1182,9 @@ def test_kmeans_plusplus_dataorder(global_random_seed):
11521182

11531183
X_fortran = np.asfortranarray(X)
11541184

1155-
centers_fortran, _ = kmeans_plusplus(X_fortran, n_clusters, random_state=global_random_seed)
1185+
centers_fortran, _ = kmeans_plusplus(
1186+
X_fortran, n_clusters, random_state=global_random_seed
1187+
)
11561188

11571189
assert_allclose(centers_c, centers_fortran)
11581190

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.