clkmeans.m
来自「聚类分析工具箱 亚历山大博士写的」· M 代码 · 共 32 行
M
32 行
% function cl = clkmeans(x,k,sfct,oldcl)
%
% DESCRIPTION
% provides cluster labels 1 to k applying k-means to x
% make sure samples (rows) in x are randomly permuted since the
% first k samples (rows) are used for initialization
% if oldcl is given their centroids are used to initalize centroids
%
% Copyright (c) 1998-2002 by Alexander Strehl
function cl = clkmeans(x,k,sfct,oldcl)
if exist('oldcl')
if (length(oldcl)==size(x,1))&(max(oldcl)==k),
disp('clkmeans: initializing means with centroids of given clustering')
[centers options cln] = kmeans(clucent(x,oldcl),x,zeros(1,14),sfct);
else
r = randperm(size(x,1));
initcenters = r(1:k);
disp(['clkmeans: initializing means with random samples ' num2str(initcenters)]);
[centers options cln] = kmeans(x(initcenters,:),x,zeros(1,14),sfct);
end;
else
disp('clkmeans: initializing means with k first samples');
[centers options cln] = kmeans(x(1:k,:),x,zeros(1,14),sfct);
end;
[x y] = find(cln);
cl = sortrows([x y]);
cl = checkcl(cl(:,2)');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?