示例#1
0
文件: nbc.py 项目: awd4/spnss
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)
示例#2
0
文件: nbc.py 项目: awd4/spnss
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