示例#1
0
文件: clustering.py 项目: gree2/hobby
def squared_clustering_errors(inputs, k):
    """find the total squared error from k-means clustering the inputs"""
    clusterer = KMeans(k)
    clusterer.train(inputs)
    means = clusterer.means
    assignments = map(clusterer.classify, inputs)

    return sum(squared_distance(input, means[cluster]) for input, cluster in zip(inputs, assignments))
示例#2
0
def squared_clustering_errors(inputs, k):
    """find the total squared error from k-means clustering the inputs"""
    clusterer = KMeans(k)
    clusterer.train(inputs)
    means = clusterer.means
    assignments = map(clusterer.classify, inputs)

    return sum(
        squared_distance(input, means[cluster])
        for input, cluster in zip(inputs, assignments))
示例#3
0
 def classify(self, input):
     """return the index of the cluster closest to the input"""
     return min(range(self.k),
                key=lambda i: squared_distance(input, self.means[i]))
示例#4
0
文件: clustering.py 项目: gree2/hobby
 def classify(self, input):
     """return the index of the cluster closest to the input"""
     return min(range(self.k), key=lambda i: squared_distance(input, self.means[i]))