dd_error.m

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

M
91
字号
function [e,f] = dd_error(x,w)%DD_ERROR compute false positive and false negative for oc_classifier%%   E = DD_ERROR(X,W)%   E = DD_ERROR(X*W)%   E = X*W*DD_ERROR%% Compute the fraction of target objects rejected and the fraction of outliers% accepted:%    E(1) = target rejected     (error on the target class)%    E(2) = outlier accepted    (error on the outlier class)% for dataset X on the trained mapping W.%%   [E,F] = DD_ERROR(X,W)%   [E,F] = DD_ERROR(X*W)%   [E,F] = X*W*DD_ERROR%% When two outputs are requested, the second output F will contain:%    F(1) = precision%    F(2) = recall`%% See also: dd_roc, gendatoc, plotroc% Copyright: D.M.J. Tax, davidt@ph.tn.tudelft.nl% Faculty of Applied Physics, Delft University of Technology% P.O. Box 5046, 2600 GA Delft, The Netherlands% Do it the same as testc:% When no input arguments are given, we just return an empty mapping:if nargin==0		% Sometimes Prtools is crazy, but fun!:	e = mapping(mfilename,'fixed');	returnelseif nargin == 1	% Now we are doing the actual work:	% true target labels	[nin,llin] = getnlab(x);	Ittrue = strmatch('target',llin);	if isempty(Ittrue), Ittrue = -1; end	Ittrue = find(nin==Ittrue);	% true outlier labels	Iotrue = strmatch('outlier',llin);	if isempty(Iotrue), Iotrue = -1; end	Iotrue = find(nin==Iotrue);	% classification labels:	lout = classd(x);	[nout,llout] = renumlab(lout);	% objects labeled target:	It = strmatch('target',llout);	if isempty(It), It = -1; end	It = (nout==It);	% objects labeled outlier:	Io = strmatch('outlier',llout);	if isempty(Io), Io = -1; end	Io = (nout==Io);	% Finally the error:	% Warning can be off, because we like to have NaN's when one of the	% classes is empty:	warning off;	e(1) = sum(It(Ittrue)==0)/length(Ittrue);	e(2) = sum(Io(Iotrue)==0)/length(Iotrue);	warning on;	% compute the precision and recall when it is requested:	if (nargout>1)		warning off;		f(1) = sum(It(Ittrue)==1)/sum(It);		f(2) = sum(It(Ittrue)==1)/length(Ittrue);		warning on;	endelse	ismapping(w);	istrained(w);	if (nargout>1)		[e,f] = feval(mfilename,x*w);	else		e = feval(mfilename,x*w);	endendreturn

⌨️ 快捷键说明

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