Пример #1
0
    def squared_clustering_errors(inputs, k):
        """ finds total squared error from k-means clustering of 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):
        """ finds total squared error from k-means clustering of 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 helper(cluster_index):
     """ calculates the squared distance between input and
     cluster vector mean """
     return squared_distance(input, self.means[cluster_index])
Пример #4
0
 def helper(cluster_index):
     """ calculates the squared distance between input and
     cluster vector mean """
     return squared_distance(input, self.means[cluster_index])