def kcluster(data, nvals): data = data.astype(np.float) from vlfwrap import KMeans km = KMeans() km.repetitions = 1 def kmeans(data, k): km.cluster(data, k) return km.quantize(data) return cluster_with_automatic_k_selection(data, nvals, kmeans)
def kcluster_fixed(data, k): data = data.astype(np.float) from vlfwrap import KMeans km = KMeans() km.repetitions = 1 km.cluster(data, k) qa = km.quantize(data) nc = qa.max() + 1 # if nc != k and len(data) >= k: # qa = np.arange(len(data)) # qa %= k # nc = k return qa, nc