8000 k-means - added support for a callable "init" argument instead of cop… · seckcoder/scikit-learn@59d7408 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59d7408

Browse files
jabergGaelVaroquaux
authored andcommitted
k-means - added support for a callable "init" argument instead of copying all the k_init parameters as optional arguments - invite user to use a lambda or something
1 parent 967cbec commit 59d7408

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

scikits/learn/cluster/k_means_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def k_means(X, k, init='k-means++', n_init=10, max_iter=300, verbose=0,
130130
seeds. The final results will be the best output of n_init consecutive
131131
runs in terms of inertia.
132132
133-
init: {'k-means++', 'random', or an ndarray}, optional
133+
init: {'k-means++', 'random', or ndarray, or a callable}, optional
134134
Method for initialization, default to 'k-means++':
135135
136136
'k-means++' : selects initial cluster centers for k-mean
@@ -190,6 +190,8 @@ def k_means(X, k, init='k-means++', n_init=10, max_iter=300, verbose=0,
190190
centers = X[seeds]
191191
elif hasattr(init, '__array__'):
192192
centers = np.asanyarray(init).copy()
193+
elif callable(init):
194+
centers = init(X, k, rng=rng)
193195
else:
194196
raise ValueError("the init parameter for the k-means should "
195197
"be 'k-mean++' or 'random' or an ndarray, "

0 commit comments

Comments
 (0)
0