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

📄 svmmatlab5.txt

📁 用SVM做分类的使用方法,有matlab代码,里面还有说明,对初学着有帮助
💻 TXT
字号:
3,用SVM做分类的使用方法

1)在matlab中输入必要的参数:X,Y,ker,C,p1,p2

  我做的测试中取的数据为:

  n = 50;
  randn('state',6);
  x1 = randn(2,n)
  y1 = ones(1,n);
  x2 = 5+randn(2,n);
  y2 = -ones(1,n);

  figure;
  plot(x1(1,:),x1(2,:),'bx',x2(1,:),x2(2,:),'k.');
  axis([-3 8 -3 8]);
  title('C-SVC')
  hold on;

  X1 = [x1,x2];

  Y1 = [y1,y2]; 

  X=X1';

  Y=Y1';

  其中,X是100*2的矩阵,Y是100*1的矩阵

  C=Inf;

  ker='linear';

  global p1 p2

  p1=3;

  p2=1;

  然后,在matlab中输入:[nsv alpha bias] = svc(X,Y,ker,C),回车之后,会显示:

  

Support Vector Classification
_____________________________
Constructing ...
Optimising ...
Execution time: 1.9 seconds
Status : OPTIMAL_SOLUTION
|w0|^2   : 0.418414
Margin   : 3.091912
Sum alpha : 0.418414
Support Vectors : 3 (3.0%)

nsv =

  3


alpha =

  0.0000
  0.0000
  0.0000
  0.0000
  0.0000

  2)输入预测函数,可以得到与预想的分类结果进行比较.

    输入:predictedY = svcoutput(X,Y,X,ker,alpha,bias),回车后得到:

  

predictedY =

  1
  1
  1
  1
  1
  1
  1
  1
  1

  3)画图

    输入:svcplot(X,Y,ker,alpha,bias),回车

⌨️ 快捷键说明

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