[Scipy-svn] r3077 - trunk/Lib/cluster
Thu Jun 7 23:42:30 CDT 2007
Date: 2007-06-07 23:42:23 -0500 (Thu, 07 Jun 2007)
New Revision: 3077
Additional init method for kmeans2, 'matrix', to avoid possible confusion between k number of components and k unique initial cluster. Close #443
--- trunk/Lib/cluster/vq.py 2007-06-08 04:14:14 UTC (rev 3076)
+++ trunk/Lib/cluster/vq.py 2007-06-08 04:42:23 UTC (rev 3077)
@@ -479,8 +479,8 @@
dimensional data, rank 2 multidimensional data, in which case one
row is one observation.
k : int or ndarray
- Number of clusters. If a ndarray is given instead, it is
- interpreted as initial cluster to use instead.
+ Number of clusters. If minit arg is 'matrix', or if a ndarray is
+ given instead, it is interpreted as initial cluster to use instead.
niter : int
Number of iterations to run.
thresh : float
@@ -495,8 +495,11 @@
points choses k points at random from the points in data.
uniform choses k points from the data such are they form a uniform
- grid od the dataset.
+ grid od the dataset (not supported yet).
+ matrix means that k has to be interpreted as initial clusters
+ (format is the same than data).
clusters : ndarray
the found clusters (one cluster per row).
@@ -517,7 +520,7 @@
# If k is not a single value, then it should be compatible with data's
- if N.size(k) > 1:
+ if N.size(k) > 1 or minit == 'matrix':
if not nd == N.ndim(k):
raise ValueError("k is not an int and has not same rank than data")
if d == 1:
@@ -529,7 +532,9 @@
clusters = k.copy()
- nc = k
+ nc = int(k)
+ if not nc == k:
+ warnings.warn("k was not an integer, was converted.")
init = _valid_init_meth[minit]
More information about the Scipy-svn