types of machine learning listing iris classification example print first observations of data frame to screennow we can clearly see variablessepal lengthsepal widthpetal lengthand petal width load in iris (flowersdata of scikit-learn import sklearn from sklearn import cluster import pandas as pd add another variable called "clusterto data frame this indicates the cluster membership of every flower in data set fit model to data all variables are considered independent variablesunsupervised learning has no target variable (ytransform iris data into pandas data frame data sklearn datasets load_iris( pd dataframe(data datacolumns list(data feature_names)print [: model cluster kmeans(n_clusters= random_state= results model fit(xx["cluster"results predict(xx["target"data target let' finally add target [" ""lookatmeiamimportantvariable (yto the data frame print [: classification_result [["cluster""target"," "]groupby(["cluster","target"]agg("count"print(classification_resultadding variable is just little trick we use to do count later the value here is arbitrary because we need column to count the rows initialize -means cluster model with clusters the random_state is random seedif you don' put it inthe seed will also be random we opt for clusters because we saw in the last listing this might be good compromise between complexity and performance three parts to this code first we select the clustertargetand columns then we group by the cluster and target columns finallywe aggregate the row of the group with simple count aggregation the matrix this classification result represents gives us an indication of whether our clustering was successful for cluster we're spot on on clusters and there has been slight mix-upbut in total we only get ( + misclassifications out of figure shows the output of the iris classification this figure shows that even without using label you' find clusters that are similar to the official iris classification with result of ( + + correct classifications out of you don' always need to choose between supervised and unsupervisedsometimes combining them is an option figure output of the iris classification