matlab SVM新函数例子

本示例使用Matlab内置的Fisher's iris数据集介绍了如何通过SVM进行二分类任务。示例中去除了一些特征并排除了setosa类别,只保留versicolor和virginica两种鸢尾花进行分类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

matlab 介绍SVM新函数时有这样一个例子:Load Fisher's iris data set. Remove the sepal lengths and widths, and all observed setosa irises.
程序:

load fisheriris %我看了一下,fisheriris是matlab系统自带的fisheriris.csv文件,里面有5列数据,151行,
第1行是项目名称:SepalLength,SepalWidth,PetalLength,PetalWidth,Species,第2行以后是5.1,3.5,1.4,0.2,setosa;。。。。等等这样的数据。
load的意思是读入fisheriris这个文件到系统里。
inds = ~strcmp(species,'setosa');%  返回值inds是一个和species有相同size的logical array,ind的元素是1或0。

    把species中的每个元素和s做比较,如果一致,则对应位置的元素为1,否则,为0。

数据文件中species列下面是'setosa'的共有50行。再取反,应该就是一列向量,前50项是0,后面100项是1。



X = meas(inds,3:4);

y = species(inds);%处理好X,y

SVMModel = fitcsvm(X,y)%生成一个分类器
SVMModel = 

  ClassificationSVM
             ResponseName: 'Y'
    CategoricalPredictors: []
               ClassNames: {'versicolor'  'virginica'}
           ScoreTransform: 'none'
          NumObservations: 100
                    Alpha: [24×1 double]
                     Bias: -14.4149
         KernelParameters: [1×1 struct]
           BoxConstraints: [100×1 double]
          ConvergenceInfo: [1×1 struct]
          IsSupportVector: [100×1 logical]
                   Solver: 'SMO'

用类似classOrder = SVMModel.ClassNames 这样的命令可以看分类器的属性
classOrder =

  2×1 cell array

    'versicolor'
    'virginica'

The first class ('versicolor') is the negative class, and the second ('virginica') is the positive class. You can change the class order during
 training by using the 'ClassNames' name-value pair argument.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值