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

14 views (last 30 days)
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!

Answers (2)

gulrukh
gulrukh on 23 Aug 2019
Hi. were you able to solve this issue?

Gideon Kassa
Gideon Kassa on 26 Sep 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);

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!