quick look at machine learning first compute the mean of the feature vectors of all the examples in the cluster if is list of feature vectors each of which is an array of numbersthe mean (more precisely the euclidean meanis the value of the expression sum( )/float(len( )given the mean and metric for computing the distance between feature vectorsthe variance of cluster is !"#$"%&!"#$%&'((!"#!)!notice that the variance is not normalized by the size of the clusterso clusters with more points are likely to look less cohesive according to this measure if one wants to compare the coherence of two clusters of different sizesone needs to divide the variance of each by the size of the cluster the definition of variance within single clusterccan be extended to define dissimilarity metric for set of clustersc!"##"$"%&'"(!"#$"%&'(!!notice that since we don' divide the variance by the size of the clustera large incoherent cluster increases the value of dissimilarity(cmore than small incoherent cluster does sois the optimization problem to find set of clusterscsuch that dissimilarity(cis minimizednot exactly it can easily be minimized by putting each example in its own cluster we need to add some constraint for examplewe could put constraint on the distance between clusters or require that the maximum number of clusters is in generalsolving this optimization problem is computationally prohibitive for most interesting problems consequentlypeople rely on greedy algorithms that provide approximate solutions later in this we present one such algorithmk-means clustering but first we will introduce some abstractions that are useful for implementing that algorithm (and other clustering algorithms as well