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))
    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))
 def helper(cluster_index):
     """ calculates the squared distance between input and
     cluster vector mean """
     return squared_distance(input, self.means[cluster_index])
 def helper(cluster_index):
     """ calculates the squared distance between input and
     cluster vector mean """
     return squared_distance(input, self.means[cluster_index])