kmeans_dd.m

来自「数据挖掘的工具箱,最新版的,希望对做这方面研究的人有用」· M 代码 · 共 65 行

M
65
字号
%KMEANS_DD k-means data description.% %       W = KMEANS_DD(A,FRACREJ,K)% % Train a k-means method with K prototypes on dataset A. Parameter% fracrej gives the fraction of the target set which will be rejected.% % Optionally, one may give the error tolerance as last argument as% stopping criterion.% % See also datasets, mappings, dd_roc% Copyright: D. Tax, R.P.W. Duin, duin@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlands  function [W,out] = kmeans_dd(a,fracrej,K,errtol)if nargin < 4,  errtol = 1e-5; endif nargin < 3 | isempty(K), K = 5; endif nargin < 2 | isempty(fracrej), fracrej = 0.05; endif nargin < 1 | isempty(a) % empty dd	W = mapping('kmeans_dd',{fracrej,K,errtol});	W = setname(W,'K-Means data description');	returnendif ~ismapping(fracrej)           %training  a = +target_class(a);     % make sure a is an OC dataset  k = size(a,2);  % train it:  [labs,w] = mykmeans(a,K,errtol);  % obtain the threshold:  d = sqrt(min(sqeucldistm(a,w),[],2));  if (size(d,2)~=1)    d = d';  end  thr = dd_threshold(d,1-fracrej);  %and save all useful data:  W.w = w;  W.threshold = thr;  W.scale = mean(d);  W = mapping('kmeans_dd','trained',W,str2mat('target','outlier'),k,2);  W = setname(W,'K-Means data description');else                               %testing  W = getdata(fracrej);  % unpack  m = size(a,1);  %compute:  out = [sqrt(min(sqeucldistm(+a,W.w),[],2)) repmat(W.threshold,m,1)];  %newout = dist2dens(out,W.scale);  newout = -out;  W = setdat(a,newout,fracrej);endreturn

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?