def squared_clustering_errors(inputs, k):
 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 ) : 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 ) ) )
finds the total squared error from k-means clustering the inputs .