0

1000x6のデータセットがあり、以下のkmeansスクリプトを使用しても問題ありませんが、クラスターの1つを出力する場合、1つの列としてのみ出力されますか?

%% cluster
opts = statset('MaxIter', 100, 'Display', 'iter');
[clustIDX, clusters, interClustSum, Dist] = kmeans(data, K, 'options',opts, ...
'distance','sqEuclidean', 'EmptyAction','singleton', 'replicates',6);

%% plot data+clusters
figure, hold on
scatter3(data(:,1),data(:,2),data(:,3), 5, clustIDX, 'filled')
scatter3(clusters(:,1),clusters(:,2),clusters(:,3), 100, (1:K)', 'filled')
hold off, xlabel('x'), ylabel('y'), zlabel('z')

%% plot clusters quality
figure
[silh,h] = silhouette(data, clustIDX);
avrgScore = mean(silh);

%% Assign data to clusters
% calculate distance (squared) of all instances to each cluster centroid
D = zeros(numObservarations, K);     % init distances
for k=1:K
%d = sum((x-y).^2).^0.5
D(:,k) = sum( ((data - repmat(clusters(k,:),numObservarations,1)).^2), 2);
end

% find  for all instances the cluster closet to it
[minDists, clusterIndices] = min(D, [], 2);

% compare it with what you expect it to be
sum(clusterIndices == clustIDX)

% Output cluster data to K datasets
K1 = data(clustIDX==1)
K2 = data(clustIDX==2)... etc

行全体の情報を出力するべきK1 = data(clustIDX==1)ではありませんか?1つの列だけでなく、元のデータセットのように6つの列ですか?それとも、これは距離を出力するだけですか?

4

1 に答える 1

2

交換

K1 = data(clustIDX==1)
K2 = data(clustIDX==2)

K1 = data(clustIDX==1,:)
K2 = data(clustIDX==2,:)

最初のものは、対応する行の最初の列のみを取得します。2つ目はそれを修正する必要があります、私は試しました、そしてそれは動作します。

于 2012-07-11T19:18:29.987 に答える