図心は、画像内の座標ではなく、フィーチャスペース内の座標に対応します。kmeansのパフォーマンスをテストする方法は2つあります。どちらの方法でも、ポイントを最も近いクラスターに最初に関連付けます。この情報は、kmeansの最初の出力から取得します。
(1)6次元空間を2次元または3次元空間に縮小し、分類の異なる座標を異なる色でプロットすることにより、クラスタリングの結果を視覚化できます。
特徴ベクトルがと呼ばれる配列に収集され、クラスターfeatureArray
を要求したとすると、mdscaleを使用して次のようにプロットし、データを3D空間に変換します。nClusters
%# kmeans clustering
[idx,centroids6D] = kmeans(featureArray,nClusters);
%# find the dissimilarity between features in the array for mdscale.
%# Add the cluster centroids to the points, so that they get transformed by mdscale as well.
%# I assume that you use Euclidean distance.
dissimilarities = pdist([featureArray;centroids6D]);
%# transform onto 3D space
transformedCoords = mdscale(dissimilarities,3);
%# create colormap with nClusters colors
cmap = hsv(nClusters);
%# loop to plot
figure
hold on,
for c = 1:nClusters
%# plot the coordinates
currentIdx = find(idx==c);
plot3(transformedCoords(currentIdx,1),transformedCoords(currentIdx,2),...
transformedCoords(currentIdx,3),'.','Color',cmap(c,:));
%# plot the cluster centroid with a black-edged square
plot3(transformedCoords(1:end-nClusters+c,1),transformedCoords(1:end-nClusters+c,2),...
transformedCoords(1:end-nClusters+c,3),'s','MarkerFaceColor',cmap(c,:),...
MarkerEdgeColor','k');
end
(2)または、画像のどの部分がどのクラスターに属しているかを示す疑似カラー画像を作成することもできます。
nRows
あなたがブロックごとに持っていると仮定してnCols
、あなたは書く
%# kmeans clustering
[idx,centroids6D] = kmeans(featureArray,nClusters);
%# create image
img = reshape(idx,nRows,nCols);
%# create colormap
cmap = hsv(nClusters);
%# show the image and color according to clusters
figure
imshow(img,[])
colormap(cmap)