'The 'Start' matrix must have the same number of columns as X.' - Error when using Kmeans

조회 수: 11 (최근 30일)
BOB
BOB 2019년 1월 22일
답변: Gideon Kassa 2021년 9월 26일
Hi,
I want to carry out an iteration of k-means clustering. I am using the tutorial found at https://uk.mathworks.com/help/stats/kmeans.html#namevaluepairarguments under the heading "Train a k-Means Clustering Algorithm". I am adapting the code for my own dataset:
k = 16
X = DATASET(:,3:6);
[idx,C] = kmeans(X,k);
plot(score(:,1),score(:,2),'k*','MarkerSize',5);
xlabel('Principal Component 1 (84.01% of Data Variability)')
ylabel('Principal Component 2 (11.33% of Data Variability)')
x1 = min(score(:,1)):0.01:max(score(:,1));
x2 = min(score(:,2)):0.01:max(score(:,2));
[x1G,x2G] = meshgrid(x1,x2);
XGrid = [x1G(:),x2G(:)]; % Defines a fine grid on the plot
idx2Region = kmeans(XGrid,k,'MaxIter',1,'Start',C);
The code works fine until the line:
idx2Region = kmeans(XGrid,3,'MaxIter',1,'Start',C);
where the error "The 'Start' matrix must have the same number of columns as X." is returned. I am not sure what this 'Start' matrix is. My dataset is a 47 x 14 double matrix.
Thanks for any help!

답변 (2개)

gulrukh
gulrukh 2019년 8월 23일
Hi. were you able to solve this issue?

Gideon Kassa
Gideon Kassa 2021년 9월 26일
Your K is 16. So rather than doing this
idx2Region = kmeans(XGrid,3,'MaxIter',1,'Start',C);
do this
idx2Region = kmeans(XGrid,16,'MaxIter',1,'Start',C);

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by