decisionboundaryplot.m

来自「一个关于数据聚类和模式识别的程序,在生物化学,化学中因该都可以用到.希望对大家有」· M 代码 · 共 48 行

M
48
字号
function out=decisionBoundaryPlot(surfObj)
% decisionBoundaryPlot: Plot of the decision boundary of a classification problem
%	Usage: out=decisionBoundaryPlot(surfObj)
%		surfObj is generated by sgcSurface.m.

%	Roger Jang, 20041201

if nargin<1, selfdemo; return; end

class=surfObj.class;
classNum=length(class);
xx=surfObj.xx;
yy=surfObj.yy;
data = [xx(:), yy(:)]';

matlabVersion=version;
matlabVersion=eval(matlabVersion(1));

hold on
for i=1:classNum
	tempClass=class;
	tempClass(i)=[];
	maxSurf=max(cat(3, tempClass.surface), [], 3);
	tt=class(i).surface-maxSurf;
	if matlabVersion==6
		[c, h]=contourf(xx, yy, tt, 0*[1 1]);
	else
		[c, h]=contourf('v6', xx, yy, tt, 0*[1 1]);
	end
	class(i).contourx=get(h(1), 'xdata');
	class(i).contoury=get(h(1), 'ydata');
	out(i)=patch('xdata', class(i).contourx, 'ydata', class(i).contoury, 'faceColor', getColorLight(i));
end
hold off
axis image;

% ====== selfdemo
function selfdemo
DS=prData('iris');
DS.input=DS.input(3:4, :);			% Only take dimensions 3 and 4 for 2d visualization
prior=getClassDataCount(DS);			% Use the class size as the class prior probability
[classParam, recogRate]=sgcTrain(DS, prior);
pointNum=50;
surfObj=sgcSurface(DS, pointNum, classParam);	% Compute the Gaussian surface for each class
decisionBoundaryPlot(surfObj);			% Plot the decision boundary
title('Decision boundaries using SGC');
sgcTrain(DS, prior, 1);				% Overlay the training data

⌨️ 快捷键说明

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