Today is too late, refer to the link first put here, tomorrow, according to their actual situation as a whole, http://www.cnblogs.com/qianlifeng/archive/2012/02/13/2350086.html
Actually encountered the source code as an example affixed.
# Show your cluster only available with 2-d data#centroids为k个类别, which holds the centroid of each category#clusterAssment为样本的标记, the first column is the category number for this sample, and the second is the distance to the centroid of this category def showcluster(DataSet, K, Centroids, clusterassment):NumSamples, Dim = Dataset.shapeifDim! =2:Print("sorry! I can not draw because the dimension of your data are not 2! ")return 1Mark = [' or ',' OB ',' og ',' OK ',' ^r ',' +r ',' SR ',' Dr ',' <r ',' PR ']ifK > Len (Mark):Print("sorry! Your K is too large! Please contact Wojiushimogui ")return 1 # Draw All Samples forIinchRange (numsamples): markindex = Int (clusterassment[i,0])#为样本指定颜色Plt.plot (Dataset[i,0], Dataset[i,1], Mark[markindex]) mark = [' Dr ',' Db ',' Dg ',' Dk ',' ^b ',' +b ',' SB ',' DB ',' <b ',' PB ']# Draw the Centroids forIinchRange (k):#画每个类的质心点Plt.plot (Centroids[i,0], Centroids[i,1], mark[i], markersize = A) Plt.show ()
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Python uses matplotlib drawing