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

📄 exoneclasssvm.m

📁 支持向量机SVM和核函数的MATLAB程序集
💻 M
字号:
%
%
%   One-Class SVM example
%


clear all
close all

randn('seed',0)
nu=0.9;
n=1000;
sigma=0.5;
[xapp,yapp]=datasets('gaussian',n,0,sigma);
xapp=xapp(find(yapp==1),:);
n=size(xapp,1);

kernel='gaussian';
kerneloption=1;
verbose=0;
[xsup,alpha,rho,pos]=svmoneclass(xapp,kernel,kerneloption,nu,verbose);
ypredapp=svmoneclassval(xapp,xsup,alpha,rho,kernel,kerneloption);
[xtest,xtest1,xtest2,nn]=DataGrid2D([-2:0.1:2],[-2:0.1:2]);


ypred=svmoneclassval(xtest,xsup,alpha,rho,kernel,kerneloption);
ypred=reshape(ypred,nn,nn);
epsilon=1e-6;
% if sum(alpha<-epsilon | alpha > (1/nu/n)+epsilon)
%     error('numerical error');
% end;
pos1=pos(find(alpha<(1/nu/n)));

%--------------- plotting
figure(1); 
%clf; 
%contourf(xtest1,xtest2,ypred,50);shading flat;
hold on
[cc,hh]=contour(xtest1,xtest2,ypred,[0 0],'k');
clabel(cc,hh); 
h1=plot(xapp(:,1),xapp(:,2),'+k'); 
set(h1,'LineWidth',2);
h3=plot(xsup(:,1),xsup(:,2),'ok'); 
set(h3,'LineWidth',2);
h1=plot(xapp(pos1,1),xapp(pos1,2),'om'); 
%axis([-2 2 -2 2])
set(gcf,'color','white');

⌨️ 快捷键说明

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