'The 'Start' matrix must have the same number of columns as X.' - Error when using Kmeans
11 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
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);
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!