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

2 visualizaciones (últimos 30 días)
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!

Respuestas (2)

gulrukh
gulrukh el 23 de Ag. de 2019
Hi. were you able to solve this issue?

Gideon Kassa
Gideon Kassa el 26 de Sept. de 2021
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);

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by