flat clustering divides the posts into set of clusters without relating the clusters to each other the goal is simply to come up with partitioning such that all posts in one cluster are most similar to each other while being dissimilar from the posts in all other clusters many flat clustering algorithms require the number of clusters to be specified up front in hierarchical clusteringthe number of clusters does not have to be specified insteadthe hierarchical clustering creates hierarchy of clusters while similar posts are grouped into one clustersimilar clusters are again grouped into one uber-cluster this is done recursivelyuntil only one cluster is leftwhich contains everything in this hierarchyone can then choose the desired number of clusters howeverthis comes at the cost of lower efficiency scikit provides wide range of clustering approaches in the package sklearn cluster you can get quick overview of the advantages and drawbacks of each of them at in the following sectionwe will use the flat clustering methodkmeansand play bit with the desired number of clusters kmeans kmeans is the most widely used flat clustering algorithm after it is initialized with the desired number of clustersnum_clustersit maintains that number of so-called cluster centroids initiallyit would pick any of the num_clusters posts and set the centroids to their feature vector then it would go through all other posts and assign them the nearest centroid as their current cluster then it will move each centroid into the middle of all the vectors of that particular class this changesof coursethe cluster assignment some posts are now nearer to another cluster so it will update the assignments for those changed posts this is done as long as the centroids move considerable amount after some iterationsthe movements will fall below threshold and we consider clustering to be converged downloading the example code you can download the example code files for all packt books you have purchased from your account at com if you purchased this book elsewhereyou can visit www packtpub com/support and register to have the files -mailed directly to you