Skip to content
This repository

MRG Cluster k rename #859

Closed
wants to merge 5 commits into from

4 participants

Andreas Mueller Varoquaux Alexandre Gramfort Gael Varoquaux
Andreas Mueller
Owner

Fixes issue #844. Renaming parameter k in KMeans, MiniBatchKMeans and SpectralClustering to n_clusters.

Varoquaux
Owner
NelleV commented

That looks good to me!
Do you know you can automatically close a ticket in the commit message, by adding closes "#ticket_number" ? The branch will then be linked to the ticket, and the ticket closed when the PR merged.

Alexandre Gramfort
Owner

I see some n_cluster and n_clusters

Andreas Mueller
Owner

@agramfort Uh oh. Should all be n_cluster. Will have a look.
@NelleV I knew that it was somehow possible. so "closes" at the very end is the keyword?

Varoquaux
Owner
NelleV commented

@amueller Yes: here is an example: NelleV/Markus@39eeaec

Andreas Mueller
Owner

Cool thanks :)

sklearn/cluster/k_means_.py
((13 lines not shown))
684 690
             init = np.asanyarray(init, dtype=np.float64)
685 691
 
686  
-        self.k = k
  692
+        if not k is None:
  693
+            n_clusters = k
  694
+            warnings.warn("Parameter k was renamed to n_clusters",
1
Gael Varoquaux Owner

I believe that this line above should be in the fit and not the init, as it violates the estimator API and will break things like clone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Gael Varoquaux
Owner

Apart from the couple of remarks above, I am +1 for merge.

Alexandre Gramfort
Owner

+1 for merge too after addressing gael's remark

Gael Varoquaux
Owner

Merged by rebase

Gael Varoquaux GaelVaroquaux closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
2  doc/modules/clustering.rst
Source Rendered
@@ -894,7 +894,7 @@ cluster analysis.
894 894
 
895 895
   >>> import numpy as np
896 896
   >>> from sklearn.cluster import KMeans
897  
-  >>> kmeans_model = KMeans(k=3, random_state=1).fit(X)
  897
+  >>> kmeans_model = KMeans(n_clusters=3, random_state=1).fit(X)
898 898
   >>> labels = kmeans_model.labels_
899 899
   >>> metrics.silhouette_score(X, labels, metric='euclidean')  
900 900
   ...                                                      # doctest: +ELLIPSIS
8  doc/tutorial/statistical_inference/unsupervised_learning.rst
Source Rendered
@@ -37,9 +37,9 @@ algorithms. The simplest clustering algorithm is the
37 37
     >>> X_iris = iris.data
38 38
     >>> y_iris = iris.target
39 39
 
40  
-    >>> k_means = cluster.KMeans(k=3)
  40
+    >>> k_means = cluster.KMeans(n_clusters=3)
41 41
     >>> k_means.fit(X_iris) # doctest: +ELLIPSIS
42  
-    KMeans(copy_x=True, init='k-means++', k=3, max_iter=300,...
  42
+    KMeans(copy_x=True, init='k-means++', ...
43 43
     >>> print k_means.labels_[::10]
44 44
     [1 1 1 1 1 0 0 0 0 0 2 2 2 2 2]
45 45
     >>> print y_iris[::10]
@@ -117,9 +117,9 @@ algorithms. The simplest clustering algorithm is the
117 117
         ...    from scipy import misc
118 118
         ...    lena = misc.lena()
119 119
     	>>> X = lena.reshape((-1, 1)) # We need an (n_sample, n_feature) array
120  
-    	>>> k_means = cluster.KMeans(k=5, n_init=1)
  120
+    	>>> k_means = cluster.KMeans(n_clusters=5, n_init=1)
121 121
     	>>> k_means.fit(X) # doctest: +ELLIPSIS
122  
-    	KMeans(copy_x=True, init='k-means++', k=5, ...
  122
+    	KMeans(copy_x=True, init='k-means++', ...
123 123
     	>>> values = k_means.cluster_centers_.squeeze()
124 124
     	>>> labels = k_means.labels_
125 125
     	>>> lena_compressed = np.choose(labels, values)
4  examples/cluster/plot_cluster_comparison.py
@@ -70,9 +70,9 @@
70 70
 
71 71
     # create clustering estimators
72 72
     ms = cluster.MeanShift(bandwidth=bandwidth, bin_seeding=True)
73  
-    two_means = cluster.MiniBatchKMeans(k=2)
  73
+    two_means = cluster.MiniBatchKMeans(n_clusters=2)
74 74
     ward_five = cluster.Ward(n_clusters=2, connectivity=connectivity)
75  
-    spectral = cluster.SpectralClustering(k=2, mode='arpack')
  75
+    spectral = cluster.SpectralClustering(n_clusters=2, mode='arpack')
76 76
     dbscan = cluster.DBSCAN(eps=.2)
77 77
     affinity_propagation = cluster.AffinityPropagation(damping=.9)
78 78
 
6  examples/cluster/plot_cluster_iris.py
@@ -38,9 +38,9 @@
38 38
 X = iris.data
39 39
 y = iris.target
40 40
 
41  
-estimators = {'k_means_iris_3': KMeans(k=3),
42  
-              'k_means_iris_8': KMeans(k=8),
43  
-              'k_means_iris_bad_init': KMeans(k=3, n_init=1, init='random'),
  41
+estimators = {'k_means_iris_3': KMeans(n_clusters=3),
  42
+              'k_means_iris_8': KMeans(n_clusters=8),
  43
+              'k_means_iris_bad_init': KMeans(n_clusters=3, n_init=1, init='random'),
44 44
              }
45 45
 
46 46
 
2  examples/cluster/plot_color_quantization.py
@@ -51,7 +51,7 @@
51 51
 print "Fitting estimator on a small sub-sample of the data"
52 52
 t0 = time()
53 53
 image_array_sample = shuffle(image_array, random_state=0)[:1000]
54  
-kmeans = KMeans(k=n_colors, random_state=0).fit(image_array_sample)
  54
+kmeans = KMeans(n_clusters=n_colors, random_state=0).fit(image_array_sample)
55 55
 print "done in %0.3fs." % (time() - t0)
56 56
 
57 57
 # Get labels for all points
9  examples/cluster/plot_kmeans_digits.py
@@ -72,16 +72,16 @@ def bench_k_means(estimator, name, data):
72 72
                                   sample_size=sample_size),
73 73
          )
74 74
 
75  
-bench_k_means(KMeans(init='k-means++', k=n_digits, n_init=10),
  75
+bench_k_means(KMeans(init='k-means++', n_clusters=n_digits, n_init=10),
76 76
               name="k-means++", data=data)
77 77
 
78  
-bench_k_means(KMeans(init='random', k=n_digits, n_init=10),
  78
+bench_k_means(KMeans(init='random', n_clusters=n_digits, n_init=10),
79 79
               name="random", data=data)
80 80
 
81 81
 # in this case the seeding of the centers is deterministic, hence we run the
82 82
 # kmeans algorithm only once with n_init=1
83 83
 pca = PCA(n_components=n_digits).fit(data)
84  
-bench_k_means(KMeans(init=pca.components_, k=n_digits, n_init=1),
  84
+bench_k_means(KMeans(init=pca.components_, n_clusters=n_digits, n_init=1),
85 85
               name="PCA-based",
86 86
               data=data)
87 87
 print 79 * '_'
@@ -90,7 +90,8 @@ def bench_k_means(estimator, name, data):
90 90
 # Visualize the results on PCA-reduced data
91 91
 
92 92
 reduced_data = PCA(n_components=2).fit_transform(data)
93  
-kmeans = KMeans(init='k-means++', k=n_digits, n_init=10).fit(reduced_data)
  93
+kmeans = KMeans(init='k-means++', n_clusters=n_digits, n_init=10)
  94
+kmeans.fit(reduced_data)
94 95
 
95 96
 # Step size of the mesh. Decrease to increase the quality of the VQ.
96 97
 h = .02     # point in the mesh [x_min, m_max]x[y_min, y_max].
9  examples/cluster/plot_kmeans_stability_low_dim_dense.py
@@ -87,11 +87,8 @@ def make_data(random_state, n_samples_per_center, grid_size, scale):
87 87
     for run_id in range(n_runs):
88 88
         X, y = make_data(run_id, n_samples_per_center, grid_size, scale)
89 89
         for i, n_init in enumerate(n_init_range):
90  
-            km = factory(k=n_clusters,
91  
-                         init=init,
92  
-                         random_state=run_id,
93  
-                         n_init=n_init,
94  
-                         **params).fit(X)
  90
+            km = factory(n_clusters=n_clusters, init=init, random_state=run_id,
  91
+                    n_init=n_init, **params).fit(X)
95 92
             inertia[i, run_id] = km.inertia_
96 93
     p = pl.errorbar(n_init_range, inertia.mean(axis=1), inertia.std(axis=1))
97 94
     plots.append(p[0])
@@ -105,7 +102,7 @@ def make_data(random_state, n_samples_per_center, grid_size, scale):
105 102
 # Part 2: Qualitative visual inspection of the convergence
106 103
 
107 104
 X, y = make_data(random_state, n_samples_per_center, grid_size, scale)
108  
-km = MiniBatchKMeans(k=n_clusters, init='random', n_init=1,
  105
+km = MiniBatchKMeans(n_clusters=n_clusters, init='random', n_init=1,
109 106
                      random_state=random_state).fit(X)
110 107
 
111 108
 fig = pl.figure()
2  examples/cluster/plot_lena_compress.py
@@ -33,7 +33,7 @@
33 33
     from scipy import misc
34 34
     lena = misc.lena()
35 35
 X = lena.reshape((-1, 1))  # We need an (n_sample, n_feature) array
36  
-k_means = cluster.KMeans(k=n_clusters, n_init=4)
  36
+k_means = cluster.KMeans(n_clusters=n_clusters, n_init=4)
37 37
 k_means.fit(X)
38 38
 values = k_means.cluster_centers_.squeeze()
39 39
 labels = k_means.labels_
2  examples/cluster/plot_lena_segmentation.py
@@ -41,7 +41,7 @@
41 41
 # Apply spectral clustering (this step goes much faster if you have pyamg
42 42
 # installed)
43 43
 N_REGIONS = 11
44  
-labels = spectral_clustering(graph, k=N_REGIONS)
  44
+labels = spectral_clustering(graph, n_clusters=N_REGIONS)
45 45
 labels = labels.reshape(lena.shape)
46 46
 
47 47
 ###############################################################################
4  examples/cluster/plot_mini_batch_kmeans.py
@@ -35,7 +35,7 @@
35 35
 ##############################################################################
36 36
 # Compute clustering with Means
37 37
 
38  
-k_means = KMeans(init='k-means++', k=3, n_init=10)
  38
+k_means = KMeans(init='k-means++', n_clusters=3, n_init=10)
39 39
 t0 = time.time()
40 40
 k_means.fit(X)
41 41
 t_batch = time.time() - t0
@@ -46,7 +46,7 @@
46 46
 ##############################################################################
47 47
 # Compute clustering with MiniBatchKMeans
48 48
 
49  
-mbk = MiniBatchKMeans(init='k-means++', k=3, batch_size=batch_size,
  49
+mbk = MiniBatchKMeans(init='k-means++', n_clusters=3, batch_size=batch_size,
50 50
                       n_init=10, max_no_improvement=10, verbose=0)
51 51
 t0 = time.time()
52 52
 mbk.fit(X)
4  examples/cluster/plot_segmentation_toy.py
@@ -70,7 +70,7 @@
70 70
 
71 71
 # Force the solver to be arpack, since amg is numerically
72 72
 # unstable on this example
73  
-labels = spectral_clustering(graph, k=4, mode='arpack')
  73
+labels = spectral_clustering(graph, n_clusters=4, mode='arpack')
74 74
 label_im = -np.ones(mask.shape)
75 75
 label_im[mask] = labels
76 76
 
@@ -88,7 +88,7 @@
88 88
 graph = image.img_to_graph(img, mask=mask)
89 89
 graph.data = np.exp(-graph.data / graph.data.std())
90 90
 
91  
-labels = spectral_clustering(graph, k=2, mode='arpack')
  91
+labels = spectral_clustering(graph, n_clusters=2, mode='arpack')
92 92
 label_im = -np.ones(mask.shape)
93 93
 label_im[mask] = labels
94 94
 
4  examples/decomposition/plot_faces_decomposition.py
@@ -93,8 +93,8 @@ def plot_gallery(title, images):
93 93
      True, False),
94 94
 
95 95
     ('Cluster centers - MiniBatchKMeans',
96  
-     MiniBatchKMeans(k=n_components, tol=1e-3, batch_size=20, max_iter=50,
97  
-                     random_state=rng),
  96
+     MiniBatchKMeans(n_cluster=n_components, tol=1e-3, batch_size=20,
  97
+         max_iter=50, random_state=rng),
98 98
      True, False)
99 99
 ]
100 100
 
5  examples/document_clustering.py
@@ -88,11 +88,12 @@
88 88
 # Do the actual clustering
89 89
 
90 90
 if opts.minibatch:
91  
-    km = MiniBatchKMeans(k=true_k, init='k-means++', n_init=1,
  91
+    km = MiniBatchKMeans(n_clusters=true_k, init='k-means++', n_init=1,
92 92
                          init_size=1000,
93 93
                          batch_size=1000, verbose=1)
94 94
 else:
95  
-    km = KMeans(k=true_k, init='random', max_iter=100, n_init=1, verbose=1)
  95
+    km = KMeans(n_clusters=true_k, init='random', max_iter=100, n_init=1,
  96
+            verbose=1)
96 97
 
97 98
 print "Clustering sparse data with %s" % km
98 99
 t0 = time()
93  sklearn/cluster/k_means_.py
@@ -33,8 +33,9 @@
33 33
 # Initialization heuristic
34 34
 
35 35
 
36  
-def k_init(X, k, n_local_trials=None, random_state=None, x_squared_norms=None):
37  
-    """Init k seeds according to k-means++
  36
+def _k_init(X, n_clusters, n_local_trials=None, random_state=None,
  37
+        x_squared_norms=None):
  38
+    """Init n_clusters seeds according to k-means++
38 39
 
39 40
     Parameters
40 41
     -----------
@@ -42,7 +43,7 @@ def k_init(X, k, n_local_trials=None, random_state=None, x_squared_norms=None):
42 43
         The data to pick seeds for. To avoid memory copy, the input data
43 44
         should be double precision (dtype=np.float64).
44 45
 
45  
-    k: integer
  46
+    n_clusters: integer
46 47
         The number of seeds to choose
47 48
 
48 49
     n_local_trials: integer, optional
@@ -73,14 +74,14 @@ def k_init(X, k, n_local_trials=None, random_state=None, x_squared_norms=None):
73 74
     n_samples, n_features = X.shape
74 75
     random_state = check_random_state(random_state)
75 76
 
76  
-    centers = np.empty((k, n_features))
  77
+    centers = np.empty((n_clusters, n_features))
77 78
 
78 79
     # Set the number of local seeding trials if none is given
79 80
     if n_local_trials is None:
80 81
         # This is what Arthur/Vassilvitskii tried, but did not report
81 82
         # specific results for other than mentioning in the conclusion
82 83
         # that it helped.
83  
-        n_local_trials = 2 + int(np.log(k))
  84
+        n_local_trials = 2 + int(np.log(n_clusters))
84 85
 
85 86
     # Pick first center randomly
86 87
     center_id = random_state.randint(n_samples)
@@ -96,8 +97,8 @@ def k_init(X, k, n_local_trials=None, random_state=None, x_squared_norms=None):
96 97
         centers[0], X, Y_norm_squared=x_squared_norms, squared=True)
97 98
     current_pot = closest_dist_sq.sum()
98 99
 
99  
-    # Pick the remaining k-1 points
100  
-    for c in xrange(1, k):
  100
+    # Pick the remaining n_clusters-1 points
  101
+    for c in xrange(1, n_clusters):
101 102
         # Choose center candidates by sampling with probability proportional
102 103
         # to the squared distance to the closest existing center
103 104
         rand_vals = random_state.random_sample(n_local_trials) * current_pot
@@ -147,9 +148,9 @@ def _tolerance(X, tol):
147 148
     return np.mean(variances) * tol
148 149
 
149 150
 
150  
-def k_means(X, k, init='k-means++', precompute_distances=True,
  151
+def k_means(X, n_clusters, init='k-means++', precompute_distances=True,
151 152
             n_init=10, max_iter=300, verbose=False,
152  
-            tol=1e-4, random_state=None, copy_x=True, n_jobs=1):
  153
+            tol=1e-4, random_state=None, copy_x=True, n_jobs=1, k=None):
153 154
     """K-means clustering algorithm.
154 155
 
155 156
     Parameters
@@ -157,7 +158,7 @@ def k_means(X, k, init='k-means++', precompute_distances=True,
157 158
     X: array-like of floats, shape (n_samples, n_features)
158 159
         The observations to cluster.
159 160
 
160  
-    k: int
  161
+    n_clusters: int
161 162
         The number of clusters to form as well as the number of
162 163
         centroids to generate.
163 164
 
@@ -229,6 +230,11 @@ def k_means(X, k, init='k-means++', precompute_distances=True,
229 230
     """
230 231
     random_state = check_random_state(random_state)
231 232
 
  233
+    if not k is None:
  234
+        n_clusters = k
  235
+        warnings.warn("Parameter k was renamed to n_clusters",
  236
+                DeprecationWarning)
  237
+
232 238
     best_inertia = np.infty
233 239
     X = as_float_array(X, copy=copy_x)
234 240
     tol = _tolerance(X, tol)
@@ -260,7 +266,7 @@ def k_means(X, k, init='k-means++', precompute_distances=True,
260 266
         for it in range(n_init):
261 267
             # run a k-means once
262 268
             labels, inertia, centers = _kmeans_single(
263  
-                X, k, max_iter=max_iter, init=init, verbose=verbose,
  269
+                X, n_clusters, max_iter=max_iter, init=init, verbose=verbose,
264 270
                 precompute_distances=precompute_distances, tol=tol,
265 271
                 x_squared_norms=x_squared_norms, random_state=random_state)
266 272
             # determine if these results are the best so far
@@ -272,10 +278,10 @@ def k_means(X, k, init='k-means++', precompute_distances=True,
272 278
         # parallelisation of k-means runs
273 279
         seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)
274 280
         results = Parallel(n_jobs=n_jobs, verbose=0)(
275  
-            delayed(_kmeans_single)(X, k, max_iter=max_iter, init=init,
276  
-                                    verbose=verbose, tol=tol,
277  
-                                    precompute_distances=precompute_distances,
278  
-                                    x_squared_norms=x_squared_norms,
  281
+            delayed(_kmeans_single)(X, n_clusters, max_iter=max_iter,
  282
+                init=init, verbose=verbose, tol=tol,
  283
+                precompute_distances=precompute_distances,
  284
+                x_squared_norms=x_squared_norms,
279 285
                                     # Change seed to ensure variety
280 286
                                     random_state=seed)
281 287
             for seed in seeds)
@@ -293,9 +299,9 @@ def k_means(X, k, init='k-means++', precompute_distances=True,
293 299
     return best_centers, best_labels, best_inertia
294 300
 
295 301
 
296  
-def _kmeans_single(X, k, max_iter=300, init='k-means++', verbose=False,
297  
-                   x_squared_norms=None, random_state=None, tol=1e-4,
298  
-                   precompute_distances=True):
  302
+def _kmeans_single(X, n_clusters, max_iter=300, init='k-means++',
  303
+        verbose=False, x_squared_norms=None, random_state=None, tol=1e-4,
  304
+        precompute_distances=True):
299 305
     """A single run of k-means, assumes preparation completed prior.
300 306
 
301 307
     Parameters
@@ -358,7 +364,7 @@ def _kmeans_single(X, k, max_iter=300, init='k-means++', verbose=False,
358 364
         x_squared_norms = _squared_norms(X)
359 365
     best_labels, best_inertia, best_centers = None, None, None
360 366
     # init
361  
-    centers = _init_centroids(X, k, init, random_state=random_state,
  367
+    centers = _init_centroids(X, n_clusters, init, random_state=random_state,
362 368
                               x_squared_norms=x_squared_norms)
363 369
     if verbose:
364 370
         print 'Initialization complete'
@@ -377,7 +383,7 @@ def _kmeans_single(X, k, max_iter=300, init='k-means++', verbose=False,
377 383
                                 distances=distances)
378 384
 
379 385
         # computation of the means is also called the M-step of EM
380  
-        centers = _centers(X, labels, k, distances)
  386
+        centers = _centers(X, labels, n_clusters, distances)
381 387
 
382 388
         if verbose:
383 389
             print 'Iteration %i, inertia %s' % (i, inertia)
@@ -565,7 +571,7 @@ def _init_centroids(X, k, init, random_state=None, x_squared_norms=None,
565 571
                 "n_samples=%d should be larger than k=%d" % (init_size, k))
566 572
 
567 573
     if init == 'k-means++':
568  
-        centers = k_init(X, k,
  574
+        centers = _k_init(X, k,
569 575
                         random_state=random_state,
570 576
                         x_squared_norms=x_squared_norms)
571 577
     elif init == 'random':
@@ -591,7 +597,7 @@ class KMeans(BaseEstimator):
591 597
     Parameters
592 598
     ----------
593 599
 
594  
-    k : int, optional, default: 8
  600
+    n_clusters : int, optional, default: 8
595 601
         The number of clusters to form as well as the number of
596 602
         centroids to generate.
597 603
 
@@ -675,14 +681,15 @@ class KMeans(BaseEstimator):
675 681
 
676 682
     """
677 683
 
678  
-    def __init__(self, k=8, init='k-means++', n_init=10, max_iter=300,
  684
+    def __init__(self, n_clusters=8, init='k-means++', n_init=10, max_iter=300,
679 685
                  tol=1e-4, precompute_distances=True,
680  
-                 verbose=0, random_state=None, copy_x=True, n_jobs=1):
  686
+                 verbose=0, random_state=None, copy_x=True, n_jobs=1, k=None):
681 687
 
682 688
         if hasattr(init, '__array__'):
683  
-            k = init.shape[0]
  689
+            n_clusters = init.shape[0]
684 690
             init = np.asanyarray(init, dtype=np.float64)
685 691
 
  692
+        self.n_clusters = n_clusters
686 693
         self.k = k
687 694
         self.init = init
688 695
         self.max_iter = max_iter
@@ -697,9 +704,9 @@ def __init__(self, k=8, init='k-means++', n_init=10, max_iter=300,
697 704
     def _check_fit_data(self, X):
698 705
         """Verify that the number of samples given is larger than k"""
699 706
         X = atleast2d_or_csr(X, dtype=np.float64)
700  
-        if X.shape[0] < self.k:
701  
-            raise ValueError("n_samples=%d should be >= k=%d" % (
702  
-                X.shape[0], self.k))
  707
+        if X.shape[0] < self.n_clusters:
  708
+            raise ValueError("n_samples=%d should be >= n_clusters=%d" % (
  709
+                X.shape[0], self.n_clusters))
703 710
         return X
704 711
 
705 712
     def _check_test_data(self, X):
@@ -724,11 +731,19 @@ def _check_fitted(self):
724 731
 
725 732
     def fit(self, X, y=None):
726 733
         """Compute k-means"""
  734
+
  735
+        if not self.k is None:
  736
+            n_clusters = self.k
  737
+            warnings.warn("Parameter k was renamed to n_clusters",
  738
+                    DeprecationWarning)
  739
+        else:
  740
+            n_clusters = self.n_clusters
  741
+
727 742
         self.random_state = check_random_state(self.random_state)
728 743
         X = self._check_fit_data(X)
729 744
 
730 745
         self.cluster_centers_, self.labels_, self.inertia_ = k_means(
731  
-            X, k=self.k, init=self.init, n_init=self.n_init,
  746
+            X, n_clusters=n_clusters, init=self.init, n_init=self.n_init,
732 747
             max_iter=self.max_iter, verbose=self.verbose,
733 748
             precompute_distances=self.precompute_distances,
734 749
             tol=self.tol, random_state=self.random_state, copy_x=self.copy_x,
@@ -945,7 +960,7 @@ class MiniBatchKMeans(KMeans):
945 960
     Parameters
946 961
     ----------
947 962
 
948  
-    k : int, optional, default: 8
  963
+    n_clusters : int, optional, default: 8
949 964
         The number of clusters to form as well as the number of
950 965
         centroids to generate.
951 966
 
@@ -1021,14 +1036,14 @@ class MiniBatchKMeans(KMeans):
1021 1036
     See http://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf
1022 1037
     """
1023 1038
 
1024  
-    def __init__(self, k=8, init='k-means++', max_iter=100,
  1039
+    def __init__(self, n_clusters=8, init='k-means++', max_iter=100,
1025 1040
                  batch_size=100, verbose=0, compute_labels=True,
1026 1041
                  random_state=None, tol=0.0, max_no_improvement=10,
1027  
-                 init_size=None, n_init=3, chunk_size=None):
  1042
+                 init_size=None, n_init=3, chunk_size=None, k=None):
1028 1043
 
1029  
-        super(MiniBatchKMeans, self).__init__(k=k, init=init,
  1044
+        super(MiniBatchKMeans, self).__init__(n_clusters=n_clusters, init=init,
1030 1045
               max_iter=max_iter, verbose=verbose, random_state=random_state,
1031  
-              tol=tol, n_init=n_init)
  1046
+              tol=tol, n_init=n_init, k=k)
1032 1047
 
1033 1048
         self.max_no_improvement = max_no_improvement
1034 1049
         if chunk_size is not None:
@@ -1052,7 +1067,7 @@ def fit(self, X, y=None):
1052 1067
         X = check_arrays(X, sparse_format="csr", copy=False,
1053 1068
                          check_ccontiguous=True, dtype=np.float64)[0]
1054 1069
         n_samples, n_features = X.shape
1055  
-        if n_samples < self.k:
  1070
+        if n_samples < self.n_clusters:
1056 1071
             raise ValueError("Number of samples smaller than number "\
1057 1072
                              "of clusters.")
1058 1073
 
@@ -1096,7 +1111,7 @@ def fit(self, X, y=None):
1096 1111
             if self.verbose:
1097 1112
                 print "Init %d/%d with method: %s" % (
1098 1113
                     init_idx + 1, self.n_init, self.init)
1099  
-            counts = np.zeros(self.k, dtype=np.int32)
  1114
+            counts = np.zeros(self.n_clusters, dtype=np.int32)
1100 1115
 
1101 1116
             # TODO: once the `k_means` function works with sparse input we
1102 1117
             # should refactor the following init to use it instead.
@@ -1104,7 +1119,7 @@ def fit(self, X, y=None):
1104 1119
             # Initialize the centers using only a fraction of the data as we
1105 1120
             # expect n_samples to be very large when using MiniBatchKMeans
1106 1121
             cluster_centers = _init_centroids(
1107  
-                X, self.k, self.init,
  1122
+                X, self.n_clusters, self.init,
1108 1123
                 random_state=self.random_state,
1109 1124
                 x_squared_norms=x_squared_norms,
1110 1125
                 init_size=init_size)
@@ -1184,10 +1199,10 @@ def partial_fit(self, X, y=None):
1184 1199
             # this is the first call partial_fit on this object:
1185 1200
             # initialize the cluster centers
1186 1201
             self.cluster_centers_ = _init_centroids(
1187  
-                X, self.k, self.init, random_state=self.random_state,
  1202
+                X, self.n_clusters, self.init, random_state=self.random_state,
1188 1203
                 x_squared_norms=x_squared_norms, init_size=self.init_size)
1189 1204
 
1190  
-            self.counts_ = np.zeros(self.k, dtype=np.int32)
  1205
+            self.counts_ = np.zeros(self.n_clusters, dtype=np.int32)
1191 1206
 
1192 1207
         _mini_batch_step(X, x_squared_norms, self.cluster_centers_,
1193 1208
                          self.counts_, np.zeros(0, np.double), 0)
35  sklearn/cluster/spectral.py
@@ -139,8 +139,8 @@ def spectral_embedding(adjacency, n_components=8, mode=None,
139 139
     return embedding
140 140
 
141 141
 
142  
-def spectral_clustering(affinity, k=8, n_components=None, mode=None,
143  
-                        random_state=None, n_init=10):
  142
+def spectral_clustering(affinity, n_clusters=8, n_components=None, mode=None,
  143
+                        random_state=None, n_init=10, k=None):
144 144
     """Apply k-means to a projection to the normalized laplacian
145 145
 
146 146
     In practice Spectral Clustering is very useful when the structure of
@@ -163,7 +163,7 @@ def spectral_clustering(affinity, k=8, n_components=None, mode=None,
163 163
           - heat kernel of the pairwise distance matrix of the samples,
164 164
           - symmetic k-nearest neighbours connectivity matrix of the samples.
165 165
 
166  
-    k: integer, optional
  166
+    n_clusters: integer, optional
167 167
         Number of clusters to extract.
168 168
 
169 169
     n_components: integer, optional, default is k
@@ -211,12 +211,15 @@ def spectral_clustering(affinity, k=8, n_components=None, mode=None,
211 211
     This algorithm solves the normalized cut for k=2: it is a
212 212
     normalized spectral clustering.
213 213
     """
  214
+    if not k is None:
  215
+        warnings.warn("'k' was renamed to n_clusters", DeprecationWarning)
  216
+        n_clusters = k
214 217
     random_state = check_random_state(random_state)
215  
-    n_components = k if n_components is None else n_components
  218
+    n_components = n_clusters if n_components is None else n_components
216 219
     maps = spectral_embedding(affinity, n_components=n_components,
217 220
                               mode=mode, random_state=random_state)
218 221
     maps = maps[1:]
219  
-    _, labels, _ = k_means(maps.T, k, random_state=random_state,
  222
+    _, labels, _ = k_means(maps.T, n_clusters, random_state=random_state,
220 223
                     n_init=n_init)
221 224
     return labels
222 225
 
@@ -235,20 +238,20 @@ class SpectralClustering(BaseEstimator):
235 238
 
236 239
     Parameters
237 240
     -----------
238  
-    k: integer, optional
  241
+    n_clusters : integer, optional
239 242
         The dimension of the projection subspace.
240 243
 
241  
-    mode: {None, 'arpack' or 'amg'}
  244
+    mode : {None, 'arpack' or 'amg'}
242 245
         The eigenvalue decomposition strategy to use. AMG requires pyamg
243 246
         to be installed. It can be faster on very large, sparse problems,
244 247
         but may also lead to instabilities
245 248
 
246  
-    random_state: int seed, RandomState instance, or None (default)
  249
+    random_state : int seed, RandomState instance, or None (default)
247 250
         A pseudo random number generator used for the initialization
248 251
         of the lobpcg eigen vectors decomposition when mode == 'amg'
249 252
         and by the K-Means initialization.
250 253
 
251  
-    n_init: int, optional, default: 10
  254
+    n_init : int, optional, default: 10
252 255
         Number of time the k-means algorithm will be run with different
253 256
         centroid seeds. The final results will be the best output of
254 257
         n_init consecutive runs in terms of inertia.
@@ -271,8 +274,12 @@ class SpectralClustering(BaseEstimator):
271 274
       http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.165.9323
272 275
     """
273 276
 
274  
-    def __init__(self, k=8, mode=None, random_state=None, n_init=10):
275  
-        self.k = k
  277
+    def __init__(self, n_clusters=8, mode=None, random_state=None, n_init=10,
  278
+            k=None):
  279
+        if not k is None:
  280
+            warnings.warn("'k' was renamed to n_clusters", DeprecationWarning)
  281
+            n_clusters = k
  282
+        self.n_clusters = n_clusters
276 283
         self.mode = mode
277 284
         self.random_state = random_state
278 285
         self.n_init = n_init
@@ -306,7 +313,7 @@ def fit(self, X):
306 313
         speeds up computation.
307 314
         """
308 315
         self.random_state = check_random_state(self.random_state)
309  
-        self.labels_ = spectral_clustering(X, k=self.k, mode=self.mode,
310  
-                                           random_state=self.random_state,
311  
-                                           n_init=self.n_init)
  316
+        self.labels_ = spectral_clustering(X, n_clusters=self.n_clusters,
  317
+                mode=self.mode, random_state=self.random_state,
  318
+                n_init=self.n_init)
312 319
         return self
89  sklearn/cluster/tests/test_k_means.py
@@ -166,7 +166,8 @@ def _check_fitted_model(km):
166 166
 
167 167
 
168 168
 def test_k_means_plus_plus_init():
169  
-    k_means = KMeans(init="k-means++", k=n_clusters, random_state=42).fit(X)
  169
+    k_means = KMeans(init="k-means++", n_clusters=n_clusters,
  170
+            random_state=42).fit(X)
170 171
     _check_fitted_model(k_means)
171 172
 
172 173
 
@@ -181,62 +182,64 @@ def _get_mac_os_version():
181 182
 def test_k_means_plus_plus_init_2_jobs():
182 183
     if _get_mac_os_version() == '10.7':
183 184
         raise SkipTest('Multi-process bug in Mac OS X Lion (see issue #636)')
184  
-    k_means = KMeans(init="k-means++", k=n_clusters, n_jobs=2,
  185
+    k_means = KMeans(init="k-means++", n_clusters=n_clusters, n_jobs=2,
185 186
                      random_state=42).fit(X)
186 187
     _check_fitted_model(k_means)
187 188
 
188 189
 
189 190
 def test_k_means_plus_plus_init_sparse():
190  
-    k_means = KMeans(init="k-means++", k=n_clusters, random_state=42)
  191
+    k_means = KMeans(init="k-means++", n_clusters=n_clusters, random_state=42)
191 192
     k_means.fit(X_csr)
192 193
     _check_fitted_model(k_means)
193 194
 
194 195
 
195 196
 def test_k_means_random_init():
196  
-    k_means = KMeans(init="random", k=n_clusters, random_state=42).fit(X)
  197
+    k_means = KMeans(init="random", n_clusters=n_clusters, random_state=42)
  198
+    k_means.fit(X)
197 199
     _check_fitted_model(k_means)
198 200
 
199 201
 
200 202
 def test_k_means_random_init_sparse():
201  
-    k_means = KMeans(init="random", k=n_clusters, random_state=42).fit(X_csr)
  203
+    k_means = KMeans(init="random", n_clusters=n_clusters, random_state=42)
  204
+    k_means.fit(X_csr)
202 205
     _check_fitted_model(k_means)
203 206
 
204 207
 
205 208
 def test_k_means_plus_plus_init_not_precomputed():
206  
-    k_means = KMeans(init="k-means++", k=n_clusters, random_state=42,
  209
+    k_means = KMeans(init="k-means++", n_clusters=n_clusters, random_state=42,
207 210
                      precompute_distances=False).fit(X)
208 211
     _check_fitted_model(k_means)
209 212
 
210 213
 
211 214
 def test_k_means_random_init_not_precomputed():
212  
-    k_means = KMeans(init="random", k=n_clusters, random_state=42,
  215
+    k_means = KMeans(init="random", n_clusters=n_clusters, random_state=42,
213 216
                      precompute_distances=False).fit(X)
214 217
     _check_fitted_model(k_means)
215 218
 
216 219
 
217 220
 def test_k_means_perfect_init():
218  
-    k_means = KMeans(init=centers.copy(), k=n_clusters, random_state=42,
219  
-                     n_init=1)
  221
+    k_means = KMeans(init=centers.copy(), n_clusters=n_clusters,
  222
+            random_state=42, n_init=1)
220 223
     k_means.fit(X)
221 224
     _check_fitted_model(k_means)
222 225
 
223 226
 
224 227
 def test_mb_k_means_plus_plus_init_dense_array():
225  
-    mb_k_means = MiniBatchKMeans(init="k-means++", k=n_clusters,
  228
+    mb_k_means = MiniBatchKMeans(init="k-means++", n_clusters=n_clusters,
226 229
                                  random_state=42)
227 230
     mb_k_means.fit(X)
228 231
     _check_fitted_model(mb_k_means)
229 232
 
230 233
 
231 234
 def test_mb_k_means_plus_plus_init_sparse_matrix():
232  
-    mb_k_means = MiniBatchKMeans(init="k-means++", k=n_clusters,
  235
+    mb_k_means = MiniBatchKMeans(init="k-means++", n_clusters=n_clusters,
233 236
                                  random_state=42)
234 237
     mb_k_means.fit(X_csr)
235 238
     _check_fitted_model(mb_k_means)
236 239
 
237 240
 
238 241
 def test_minibatch_init_with_large_k():
239  
-    mb_k_means = MiniBatchKMeans(init='k-means++', init_size=10, k=20)
  242
+    mb_k_means = MiniBatchKMeans(init='k-means++', init_size=10, n_clusters=20)
240 243
     # Check that a warning is raised, as the number clusters is larger
241 244
     # than the init_size
242 245
     with warnings.catch_warnings(record=True) as warn_queue:
@@ -247,26 +250,26 @@ def test_minibatch_init_with_large_k():
247 250
 
248 251
 def test_minibatch_k_means_random_init_dense_array():
249 252
     # increase n_init to make random init stable enough
250  
-    mb_k_means = MiniBatchKMeans(init="random", k=n_clusters,
  253
+    mb_k_means = MiniBatchKMeans(init="random", n_clusters=n_clusters,
251 254
                                  random_state=42, n_init=10).fit(X)
252 255
     _check_fitted_model(mb_k_means)
253 256
 
254 257
 
255 258
 def test_minibatch_k_means_random_init_sparse_csr():
256 259
     # increase n_init to make random init stable enough
257  
-    mb_k_means = MiniBatchKMeans(init="random", k=n_clusters,
  260
+    mb_k_means = MiniBatchKMeans(init="random", n_clusters=n_clusters,
258 261
                                  random_state=42, n_init=10).fit(X_csr)
259 262
     _check_fitted_model(mb_k_means)
260 263
 
261 264
 
262 265
 def test_minibatch_k_means_perfect_init_dense_array():
263  
-    mb_k_means = MiniBatchKMeans(init=centers.copy(), k=n_clusters,
  266
+    mb_k_means = MiniBatchKMeans(init=centers.copy(), n_clusters=n_clusters,
264 267
                                  random_state=42).fit(X)
265 268
     _check_fitted_model(mb_k_means)
266 269
 
267 270
 
268 271
 def test_minibatch_k_means_perfect_init_sparse_csr():
269  
-    mb_k_means = MiniBatchKMeans(init=centers.copy(), k=n_clusters,
  272
+    mb_k_means = MiniBatchKMeans(init=centers.copy(), n_clusters=n_clusters,
270 273
                                  random_state=42).fit(X_csr)
271 274
     _check_fitted_model(mb_k_means)
272 275
 
@@ -281,7 +284,7 @@ def test_init(X, k, random_state):
281 284
 
282 285
 
283 286
 def test_mini_batch_k_means_random_init_partial_fit():
284  
-    km = MiniBatchKMeans(k=n_clusters, init="random", random_state=42)
  287
+    km = MiniBatchKMeans(n_clusters=n_clusters, init="random", random_state=42)
285 288
 
286 289
     # use the partial_fit API for online learning
287 290
     for X_minibatch in np.array_split(X, 10):
@@ -293,14 +296,14 @@ def test_mini_batch_k_means_random_init_partial_fit():
293 296
 
294 297
 
295 298
 def test_minibatch_default_init_size():
296  
-    mb_k_means = MiniBatchKMeans(init=centers.copy(), k=n_clusters,
  299
+    mb_k_means = MiniBatchKMeans(init=centers.copy(), n_clusters=n_clusters,
297 300
                                  batch_size=10, random_state=42).fit(X)
298 301
     assert_equal(mb_k_means.init_size_, 3 * mb_k_means.batch_size)
299 302
     _check_fitted_model(mb_k_means)
300 303
 
301 304
 
302 305
 def test_minibatch_set_init_size():
303  
-    mb_k_means = MiniBatchKMeans(init=centers.copy(), k=n_clusters,
  306
+    mb_k_means = MiniBatchKMeans(init=centers.copy(), n_clusters=n_clusters,
304 307
                                  init_size=666, random_state=42).fit(X)
305 308
     assert_equal(mb_k_means.init_size, 666)
306 309
     assert_equal(mb_k_means.init_size_, n_samples)
@@ -308,19 +311,20 @@ def test_minibatch_set_init_size():
308 311
 
309 312
 
310 313
 def test_k_means_invalid_init():
311  
-    k_means = KMeans(init="invalid", n_init=1, k=n_clusters)
  314
+    k_means = KMeans(init="invalid", n_init=1, n_clusters=n_clusters)
312 315
     assert_raises(ValueError, k_means.fit, X)
313 316
 
314 317
 
315 318
 def test_mini_match_k_means_invalid_init():
316  
-    k_means = MiniBatchKMeans(init="invalid", n_init=1, k=n_clusters)
  319
+    k_means = MiniBatchKMeans(init="invalid", n_init=1, n_clusters=n_clusters)
317 320
     assert_raises(ValueError, k_means.fit, X)
318 321
 
319 322
 
320 323
 def test_k_means_copyx():
321 324
     """Check if copy_x=False returns nearly equal X after de-centering."""
322 325
     my_X = X.copy()
323  
-    k_means = KMeans(copy_x=False, k=n_clusters, random_state=42).fit(my_X)
  326
+    k_means = KMeans(copy_x=False, n_clusters=n_clusters, random_state=42)
  327
+    k_means.fit(my_X)
324 328
     _check_fitted_model(k_means)
325 329
 
326 330
     # check if my_X is centered
@@ -337,7 +341,7 @@ def test_k_means_non_collapsed():
337 341
     """
338 342
     my_X = np.array([[1.1, 1.1], [0.9, 1.1], [1.1, 0.9], [0.9, 1.1]])
339 343
     array_init = np.array([[1.0, 1.0], [5.0, 5.0], [-5.0, -5.0]])
340  
-    k_means = KMeans(init=array_init, k=3, random_state=42, n_init=1)
  344
+    k_means = KMeans(init=array_init, n_clusters=3, random_state=42, n_init=1)
341 345
     k_means.fit(my_X)
342 346
 
343 347
     # centers must not been collapsed
@@ -350,7 +354,7 @@ def test_k_means_non_collapsed():
350 354
 
351 355
 
352 356
 def test_predict():
353  
-    k_means = KMeans(k=n_clusters, random_state=42)
  357
+    k_means = KMeans(n_clusters=n_clusters, random_state=42)
354 358
 
355 359
     k_means.fit(X)
356 360
 
@@ -368,13 +372,15 @@ def test_predict():
368 372
 
369 373
 
370 374
 def test_score():
371  
-    s1 = KMeans(k=n_clusters, max_iter=1, random_state=42).fit(X).score(X)
372  
-    s2 = KMeans(k=n_clusters, max_iter=10, random_state=42).fit(X).score(X)
  375
+    km1 = KMeans(n_clusters=n_clusters, max_iter=1, random_state=42)
  376
+    s1 = km1.fit(X).score(X)
  377
+    km2 = KMeans(n_clusters=n_clusters, max_iter=10, random_state=42)
  378
+    s2 = km2.fit(X).score(X)
373 379
     assert_greater(s2, s1)
374 380
 
375 381
 
376 382
 def test_predict_minibatch_dense_input():
377  
-    mb_k_means = MiniBatchKMeans(k=n_clusters, random_state=40).fit(X)
  383
+    mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, random_state=40).fit(X)
378 384
 
379 385
     # sanity check: predict centroid labels
380 386
     pred = mb_k_means.predict(mb_k_means.cluster_centers_)
@@ -386,7 +392,7 @@ def test_predict_minibatch_dense_input():
386 392
 
387 393
 
388 394
 def test_predict_minibatch_kmeanspp_init_sparse_input():
389  
-    mb_k_means = MiniBatchKMeans(k=n_clusters, init='k-means++',
  395
+    mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, init='k-means++',
390 396
                                  n_init=10).fit(X_csr)
391 397
 
392 398
     # sanity check: re-predict labeling for training set samples
@@ -402,7 +408,7 @@ def test_predict_minibatch_kmeanspp_init_sparse_input():
402 408
 
403 409
 
404 410
 def test_predict_minibatch_random_init_sparse_input():
405  
-    mb_k_means = MiniBatchKMeans(k=n_clusters, init='random',
  411
+    mb_k_means = MiniBatchKMeans(n_clusters=n_clusters, init='random',
406 412
                                  n_init=10).fit(X_csr)
407 413
 
408 414
     # sanity check: re-predict labeling for training set samples
@@ -424,18 +430,19 @@ def test_input_dtypes():
424 430
     init_int = X_int[:2]
425 431
 
426 432
     fitted_models = [
427  
-        KMeans(k=2).fit(X_list),
428  
-        KMeans(k=2).fit(X_int),
429  
-        KMeans(k=2, init=init_int, n_init=1).fit(X_list),
430  
-        KMeans(k=2, init=init_int, n_init=1).fit(X_int),
  433
+        KMeans(n_clusters=2).fit(X_list),
  434
+        KMeans(n_clusters=2).fit(X_int),
  435
+        KMeans(n_clusters=2, init=init_int, n_init=1).fit(X_list),
  436
+        KMeans(n_clusters=2, init=init_int, n_init=1).fit(X_int),
431 437
         # mini batch kmeans is very unstable on such a small dataset hence
432 438
         # we use many inits
433  
-        MiniBatchKMeans(k=2, n_init=10, batch_size=2).fit(X_list),
434  
-        MiniBatchKMeans(k=2, n_init=10, batch_size=2).fit(X_int),
435  
-        MiniBatchKMeans(k=2, n_init=10, batch_size=2).fit(X_int_csr),
436  
-        MiniBatchKMeans(k=2, batch_size=2, init=init_int).fit(X_list),
437  
-        MiniBatchKMeans(k=2, batch_size=2, init=init_int).fit(X_int),
438  
-        MiniBatchKMeans(k=2, batch_size=2, init=init_int).fit(X_int_csr),
  439
+        MiniBatchKMeans(n_clusters=2, n_init=10, batch_size=2).fit(X_list),
  440
+        MiniBatchKMeans(n_clusters=2, n_init=10, batch_size=2).fit(X_int),
  441
+        MiniBatchKMeans(n_clusters=2, n_init=10, batch_size=2).fit(X_int_csr),
  442
+        MiniBatchKMeans(n_clusters=2, batch_size=2, init=init_int).fit(X_list),
  443
+        MiniBatchKMeans(n_clusters=2, batch_size=2, init=init_int).fit(X_int),
  444
+        MiniBatchKMeans(n_clusters=2, batch_size=2,
  445
+            init=init_int).fit(X_int_csr),
439 446
     ]
440 447
     expected_labels = [0, 1, 1, 0, 0, 1]
441 448
     scores = np.array([v_measure_score(expected_labels, km.labels_)
@@ -444,7 +451,7 @@ def test_input_dtypes():
444 451
 
445 452
 
446 453
 def test_transform():
447  
-    k_means = KMeans(k=n_clusters)
  454
+    k_means = KMeans(n_clusters=n_clusters)
448 455
     k_means.fit(X)
449 456
     X_new = k_means.transform(k_means.cluster_centers_)
450 457
 
@@ -462,7 +469,7 @@ def test_n_init():
462 469
     inertia = np.zeros((len(n_init_range), n_runs))
463 470
     for i, n_init in enumerate(n_init_range):
464 471
         for j in range(n_runs):
465  
-            km = KMeans(k=n_clusters, init="random", n_init=n_init,
  472
+            km = KMeans(n_clusters=n_clusters, init="random", n_init=n_init,
466 473
                         random_state=j).fit(X)
467 474
             inertia[i, j] = km.inertia_
468 475
 
6  sklearn/cluster/tests/test_spectral.py
@@ -22,7 +22,7 @@ def test_spectral_clustering():
22 22
                  ])
23 23
 
24 24
     for mat in (S, sparse.csr_matrix(S)):
25  
-        model = SpectralClustering(random_state=0, k=2).fit(mat)
  25
+        model = SpectralClustering(random_state=0, n_clusters=2).fit(mat)
26 26
         labels = model.labels_
27 27
         if labels[0] == 0:
28 28
             labels = 1 - labels
@@ -30,7 +30,7 @@ def test_spectral_clustering():
30 30
         assert_equal(labels, [1, 1, 1, 0, 0, 0, 0])
31 31
 
32 32
         model_copy = loads(dumps(model))
33  
-        assert_equal(model_copy.k, model.k)
  33
+        assert_equal(model_copy.n_clusters, model.n_clusters)
34 34
         assert_equal(model_copy.mode, model.mode)
35 35
         assert_equal(model_copy.random_state.get_state(),
36 36
                      model.random_state.get_state())
@@ -55,7 +55,7 @@ def test_spectral_clustering_sparse():
55 55
 
56 56
     S = sparse.coo_matrix(S)
57 57
 
58  
-    labels = SpectralClustering(random_state=0, k=2).fit(S).labels_
  58
+    labels = SpectralClustering(random_state=0, n_clusters=2).fit(S).labels_
59 59
     if labels[0] == 0:
60 60
         labels = 1 - labels
61 61
 
2  sklearn/hmm.py
@@ -719,7 +719,7 @@ def _init(self, obs, params='stmc'):
719 719
 
720 720
         if 'm' in params:
721 721
             self._means_ = cluster.KMeans(
722  
-                k=self.n_components).fit(obs[0]).cluster_centers_
  722
+                n_clusters=self.n_components).fit(obs[0]).cluster_centers_
723 723
         if 'c' in params:
724 724
             cv = np.cov(obs[0].T)
725 725
             if not cv.shape:
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.