main content

cluster evaluation -凯发k8网页登录

this example shows how to identify clusters in fisher's iris data.

load fisher's iris data set.

load fisheriris
x = meas;
y = categorical(species);

x is a numeric matrix that contains two petal measurements for 150 irises. y is a cell array of character vectors that contains the corresponding iris species.

evaluate multiple clusters from 1 to 10.

eva = evalclusters(x,'kmeans','calinskiharabasz','klist',1:10)
eva = 
  calinskiharabaszevaluation with properties:
    numobservations: 150
         inspectedk: [1 2 3 4 5 6 7 8 9 10]
    criterionvalues: [nan 513.9245 561.6278 530.4871 456.1279 469.5068 449.6410 435.8182 413.3837 386.5571]
           optimalk: 3

the optimalk value indicates that, based on the calinski-harabasz criterion, the optimal number of clusters is three.

visualize eva to see the results for each number of clusters.

plot(eva)

figure contains an axes object. the axes object with xlabel number of clusters, ylabel calinskiharabasz values contains 2 objects of type line.

most clustering algorithms need prior knowledge of the number of clusters. when this information is not available, use cluster evaluation techniques to determine the number of clusters present in the data based on a specified metric.

three clusters is consistent with the three species in the data.

categories(y)
ans = 3x1 cell
    {'setosa'    }
    {'versicolor'}
    {'virginica' }

compute a nonnegative rank-two approximation of the data for visualization purposes.

xred = nnmf(x,2);

the original features are reduced to two features. since none of the features are negative, nnmf also guarantees that the features are nonnegative.

confirm the three clusters visually using a scatter plot.

gscatter(xred(:,1),xred(:,2),y)
xlabel('column 1')
ylabel('column 2')
grid on

figure contains an axes object. the axes object with xlabel column 1, ylabel column 2 contains 3 objects of type line. one or more of the lines displays its values using only markers these objects represent setosa, versicolor, virginica.

see also

|

网站地图