⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classification_error.m

📁 模式识别matlab工具箱,包括SVM,ICA,PCA,NN等等模式识别算法,很有参考价值
💻 M
字号:
function [classify, err] = classification_error(D, features, targets, region)

%Find a classification error for a given decision surface D and a given set of
%features (2xL) and targets (1xL)
%The features are assumed to lay in a box defined by region
%([-x x -y y ... number_of_points])


N		= region(length(region));			%Number of points on the grid
N0		= length(find(targets == 0));		%Number of targets from class 0
N1		= length(find(targets == 1));		%Number of targets from class 1
Dims	= size(features,1);					%Number of data dimentions
ok0	= 0;
ok1	= 0;

%Normalize the features according to the grid, and then check each point if it is
%classified correctly or not.
for i = 1:Dims,
   base = (i-1)*2;
	features(i,:) = round(1/(region(base+2)-region(base+1))*...
      ((N-1)*features(i,:)+region(base+2)-N*region(base+1)));
end

switch Dims,
case 2,
   for i = 1:N0+N1,
      %Get the feature, but if for some reason it is out of range, put it on the edge of the range
      feature1 = min(max(1,features(1,i)),region(5));
      feature2 = min(max(1,features(2,i)),region(5));
   	if (targets(i)),
      	ok1		 = ok1 + (D(feature2,feature1) == 1);
	   else    
   	   ok0		 = ok0 + (D(feature2,feature1) == 0);
      end 
   end
case 3,
   for i = 1:N0+N1,
      feature1 = min(max(1,features(1,i)),region(5));
      feature2 = min(max(1,features(2,i)),region(5));
      feature3 = min(max(1,features(3,i)),region(5));
   	if (targets(i)),
      	ok1		 = ok1 + (D(feature2,feature1,feature3) == 1);
	   else    
   	   ok0		 = ok0 + (D(feature2,feature1,feature3) == 0);
      end 
   end
otherwise
   error('The toolbox can assess the error for two or three dimensional data only.')
end


classify 		= zeros(2);
classify(1,1)  = ok0/N0;
classify(1,2)  = (N0-ok0)/N0;
classify(2,2)  = ok1/N1;
classify(2,1)  = (N1-ok1)/N1;

err = (N0*classify(1,2) + N1*classify(2,1))/(N0+N1);

⌨️ 快捷键说明

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