手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

matlab svm工具箱

时间:2025-01-04 23:01:50

1、7种支持向量机SVM工具包:LIBSVM(台湾大学林智仁,详细说明可查看其主页)、Mysvm(作者:stefan ruping)、SVMlight(作者:Thorsten Joachims)、LS_SVM、OSU_SVM、Stprtool、SVM_SteveGunn.最后面四个,海军工程大学的陆振波做过一些整理,详细说明可查看其主页http://luzhenbo.88uu.com.cn/

2、matlab自带工具箱:主要是svmtrain和svmclassify函数(训练和分类函数)svmtrain用法:SVMStruct = svmtrain(..., 'Kernel_Function', Kernel_FunctionValue, ...) SVMStruct = svmtrain(..., 'RBF_Sigma', RBFSigmaValue, ...) SVMStruct = svmtrain(..., 'Polyorder', PolyorderValue, ...) SVMStruct = svmtrain(..., 'Mlp_Params', Mlp_ParamsValue, ...) SVMStruct = svmtrain(..., 'Method', MethodValue, ...) SVMStruct = svmtrain(..., 'QuadProg_Opts', QuadProg_OptsValue, ...)例如:svmStruct= svmtrain(data(train,:),groups(train),'Kernel_Function','quadratic','Method', 'LS','showplot',true);% %核函数,二次;;;方法,最小二乘参数解释:1、'kernel_function'(核函数),核函数有:'linear' (线性)默认、'quadratic' (二次)、'polynomial' (多项式默认三阶)、'rbf'(高斯径向基函数)。'rbf'比较好用,其参数包括惩罚因子C和核参数g2、寻找超平面的方法:1 'SMO'默认 - Sequential Minimal Optimization (SMO) method (default). It implements the L1 soft-margin SVM classifier.、2'QP' 二次规划- Quadratic programming (requires an Optimization Toolbox license). It implements the L2 soft-margin SVM classifier. Method 'QP' doesn't scale well for TRAINING with large number of observations.、3'LS'最小二乘 - Least-squares method. It implements the L2 soft-margin SVM classifier.e.g.clc;clear allload fisheriris %载入matlab自带的数据[有关数据的信息可以自己到UCI查找,这是UCI的经典数据之一],% UCI数据库http://archive.ics.uci.edu/ml/该数据库得到大家认可%其中meas是150*4的矩阵代表着有150个样本每个样本有4个属性描述%species代表着这150个样本的分类data = [meas(:,1), meas(:,2)]; %在这里只取meas的第一列和第二列,即只选取前两个属性.groups = ismember(species,'setosa');%由于species分类中是有三个分类:setosa,versicolor,virginica,为了使问题简单,我们将其变为二分类问题:Setosa%and non-Setosa,groups中只有0和1[train, test] = crossvalind('holdOut',groups);%生成索引,一部分用来训练,其他部分用来测试cp = classperf(groups);%随机选择训练集合测试集,其中cp作用是后来用来评价分类器的.*/svmStruct = svmtrain(data(train,:),groups(train),'showplot',true);%svmStruct= svmtrain(data(train,:),groups(train),'Kernel_Function','rbf','RBF_Sigma',1,'boxconstraint',1,'showplot',true);%使用svmtrain进行训练,得到训练后的结构svmStruct,在预测时使用.

3、Libsvm工具箱公认最好用下载地址 http://www.csie.ntu.edu.tw/~cjlin/libsvm/配置matlab2014a方法:http://www.itnose.net/detail/6236932.html0将工作目录改变为工具箱所在位置(打开工具箱)1add path,添加工具箱所在位置(打开工具箱)2-mex up -mex up c++3make(对于六十四位需要打开make文件,并且将-o用-largeArrayDims替换)load wine.data;data=[wine(:,1),wine(:,2)];groups=ismember(wine(:,1),1);[train, test] = crossvalind('holdOut',groups);train_wine=data(train,:);train_wine_labels=groups(train,:);train_wine_labels=double(train_wine_labels);test_wine=data(train,:);test_wine_labels=groups(test,:);test_wine_labels=double(test_wine_labels);model = svmtrain(train_wine_labels, train_wine, '-c 1 -g 0.07');%二分[predict_label,accuary]=svmpredict(test_wine_labels,test_wine,model)Options:-s svm类型:设置SVM模型类型(默认0)0 -- C-SVC1 -- nu-SVC2 -- one-class SVM3 -- epsilon-SVR4 -- nu-SVR-t 核函数类型:核函数设置类型(默认2)0 -- 线性核函数: u'*v1 -- 多项式核函数: (gamma*u'*v + coef0)^degree2 -- RBF核函数: exp(-gamma*|u-v|^2)3 -- sigmoid核函数: tanh(gamma*u'*v + coef0)4 -- 预定义核函数(指定核矩阵)-d degree:核函数中的degree设置(针对多项式核函数)(默认3)-g gama:核函数中的gamma函数设置(针对多项式/rbf/sigmoid核函数)(默认1/num_features,即属性数目的倒数)-r coef0:核函数中的coef0设置(针对多项式/sigmoid核函数)(默认0)-c cost:设置C-SVC,epsilon-SVR和nu-SVC的参数(损失函数)(默认1)-n nu:设置nu-SVC,one-class SVM和nu-SVR的参数(默认0.5)-p epsilon:设置epsilon-SVR中损失函数epsilon的值(默认0.1)-m cachesize:设置cache内存大小,以MB为单位(默认100)-e eps:设置允许的终止判据(默认0.001)-h shrinking:是否使用启发式,0或1(默认1)-wi weight:设置第几类的参数C为weight*C(C-SVC中的C)(默认1)-v n: n-fold交互检验模式,n为fold的个数,必须大于等于2 参数 -v 随机地将数据剖分为n部分并计算交互检验准确度和均方根误差。 以上这些参数设置可以按照SVM的类型和核函数所支持的参数进行任意组合,如果设置的参数在函数或SVM类型中没有也不会产生影响,程序不会接受该参数;如果应有的参数设置不正确,参数将采用默认值。

4、训练好的 model贮存与使用save example1 model%将训练好的model储存为example1load example1.mat

© 手抄报圈