'The 'Start' matrix must have the same number of columns as X.' - Error when using Kmeans
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Gideon Kassa
am 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);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!