资源简介
svm分类与回归的matlab代码

代码片段和文件信息
% 使用libsvm进行分类,只需要有属性矩阵和标签,然后建立分类模型(model),然后利用得到的这个model进行分类预测。
% 举例说明分类
%一个班级里面有两个男生(男生1、男生2),两个女生(女生1、女生2),其中
% 男生1 身高:176cm 体重:70kg;
% 男生2 身高:180cm 体重:80kg;
%
% 女生1 身高:161cm 体重:45kg;
% 女生2 身高:163cm 体重:47kg;
% 将男生定义为1,女生定义为-1
data = [176 70;180 80;161 45;163 47];%属性矩阵,data矩阵为属性矩阵,行数4代表有4个样本,列数2表示属性有两个
label = [1;1;-1;-1];%在label中存入男女生类别标签(1、-1)
model = svmtrain(labeldata);%由属性矩阵data和标签label就可以利用libsvm建立分类模型
testdata = [190 85];%测试数据,已知身高190cm,体重85kg,但是性别未知
testdatalabel = -1; %假设其标签为-1
[predictlabelaccuracy] = svmpredict(testdatalabeltestdatamodel);
predictlabel %通过预测我们得知这个新来的学生的标签是1(男生),由于原本我们假设其标签为-1,假设错误,所以分类准确率为0%。
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% 使用libsvm工具箱本身带的测试数据heart_scale来实际进行一下测试
tic;
close all;
clear;
clc;
format compact;
%%
% 首先载入数据
load heart_scale;
data = heart_scale_inst;
label = heart_scale_label;
% 选取前200个数据作为训练集合,后70个数据作为测试集合
ind = 200;
traindata = data(1:ind:);
trainlabel = label(1:ind:);
testdata = data(ind+1:end:);
testlabel = label(ind+1:end:);
% 利用训练集合建立分类模型
model = svmtrain(trainlabeltraindata‘-s 0 -t 2 -c 1.2 -g 2.8‘);
% 分类模型model解密
model
Parameters = model.Parameters
Label = model.Label
nr_class = model.nr_class
totalSV = model.totalSV
nSV = model.nSV
% 利用建立的模型看其在训练集合上的分类效果
[ptrainacctrain] = svmpredict(trainlabeltraindatamodel);
% 预测测试集合标签
[ptestacctest] = svmpredict(testlabeltestdatamodel);
%%
toc;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% libsvm_options:
% -s svm_type : set type of SVM (default 0)
% 0 -- C-SVC
% 1 -- nu-SVC
% 2 -- one-class SVM
% 3 -- epsilon-SVR
% 4 -- nu-SVR
% -t kernel_type : set type of kernel function (default 2)
% 0 -- linear: u‘*v
% 1 -- polynomial: (gamma*u‘*v + coef0)^degree
% 2 -- radial basis function: exp(-gamma*|u-v|^2)
% 3 -- sigmoid: tanh(gamma*u‘*v + coef0)
% 4 -- precomputed kernel (kernel values in training_instance_matrix)
% -d degree : set degree in kernel function (default 3)
% -g gamma : set gamma in kernel function (default 1/k)
% -r coef0 : set coef0 in kernel function (default 0)
% -c cost : set the parameter C of C-SVC epsilon-SVR and nu-SVR (default 1)
% -n nu : set the parameter nu of nu-SVC one-class SVM and nu-SVR (default
%
% 0.5)
% -p epsilon : set the epsilon in loss function of epsilon-SVR (default 0.1)
% -m cachesize : set cache memory size in MB (default 100)
% -e epsilon : set tolerance of term
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 324422 2015-04-07 17:08 SVM分类与回归\libsvm_library.pdf
文件 5154 2015-04-06 23:30 SVM分类与回归\SVM分类小例子.m
文件 1041 2015-04-06 23:42 SVM分类与回归\SVM回归小例子.m
文件 1397537 2014-12-18 14:12 SVM分类与回归\支持向量机通俗导论(理解SVM的三层境界)Latex版.pdf
目录 0 2015-04-20 15:38 SVM分类与回归
----------- --------- ---------- ----- ----
1728154 5
相关资源
- 串行级联cpm系统MATLAB仿真
- matlab_OFDM调制解调(来自剑桥大学)
- Matlab路面裂缝识别69319
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
评论
共有 条评论