machine learning figure the goal of clustering is to divide data set into "sufficiently distinctsubsets in this plot for instancethe observations have been divided into three clusters -means is good general-purpose algorithm with which to get started howeverlike all the clustering algorithmsyou need to specify the number of desired clusters in advancewhich necessarily results in process of trial and error before reaching decent conclusion it also presupposes that all the data required for analysis is available already what if it wasn'tlet' look at the actual case of clustering irises (the flowerby their properties (sepal length and widthpetal length and widthand so onin this example we'll use the -means algorithm it' good algorithm to get an impression of the data but it' sensitive to start valuesso you can end up with different cluster every time you run the algorithm unless you manually define the start values by specifying seed (constant for the start value generatorif you need to detect hierarchyyou're better off using an algorithm from the class of hierarchical clustering techniques one other disadvantage is the need to specify the number of desired clusters in advance this often results in process of trial and error before coming to satisfying conclusion executing the code is fairly simple it follows the same structure as all the other analyses except you don' have to pass target variable it' up to the algorithm to learn interesting patterns the following listing uses an iris data set to see if the algorithm can group the different types of irises