Bonjour,
Cet algorithme utilise-t-il la distance euclidienne ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 function label = MyKMeans(X, k) n = size(X,2); last = 0; label = ceil(k*rand(1,n)); % Initialisation aléatoire % while any(label ~= last) E = sparse(1:n,label,1,n,k,n); m = X*(E*spdiags(1./sum(E,1)',0,k,k)); % Claculer m de chaque classe last = label; [w,label] = max(bsxfun(@minus,m'*X,dot(m,m,1)'/2),[],1); % Affecter les individus au plus proche centre de gravite end
Merci
(Source : litekmeans.m par Michael Chen)
Partager