资源简介
Iris 是一种鸢尾属植物。在数据记录中,每组数据包含Iris花的四种属性:萼片长度,萼片宽度,花瓣长度,和花瓣宽度,三种不同的花各有50组数据. 这样总共有150组数据或模式。此为基于matlab的Iris花的三分类程序。
代码片段和文件信息
clear;
irisData = dlmread(‘iris.data‘);
% irisData is 150x5.
% row:
% Sepal.Length Sepal.Width Petal.Length Petal.Width Group(12or 3)
% the first 50x5 is Isis-setosa(1)
% the second 50x5 is Isis-versicolor(2)
% the last 50x5 is Isis-virginica(3).
%
% !!! Caution !!!
% X(50 + 21 :) equals X(50 + 50 + 27 :) but Y(50 + 50 + 21) DOESNOT equal Y(50 + 50 + 27)!
% So the algorithm will NEVER be 100% correct.
plotAxis = [min(irisData(: 3)) max(irisData(: 3)) min(irisData(: 4)) max(irisData(: 4))];
kernel = ‘rbf‘;
c = [1 10 100 1000 10000];
sigma = 1 : 0.5: 3;
[C Sigma] = meshgrid(c sigma);
C = C(:);
Sigma = Sigma(:);
Err = zeros(size(C));
n = length(Err);
Xtest = irisData(1 : 150 3 : 4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% First train Isis-setosa(1) and Isis-versicolor(2) using grid search.
%
disp(‘.....................................................................‘)
X = irisData(1 : 100 3 : 4);
Y = irisData(1 : 100 5);
Y(find(Y==1)) = 1;
Y(find(Y==2)) = -1;
Xtrain = X;
disp(‘Training Isis-setosa(1) and Isis-versicolor(2) using grid search.‘)
disp(‘Please wait a while.‘);
for i = 1 : n
[alphaStar bStar SVIndex] = yxcSVMtrain(X Y C(i) kernel Sigma(i));
[YClassified Z Err(i)] = yxcSVMclassifer(Xtrain Xtrain Y alphaStar bStar kernel Sigma(i));
%disp(sprintf(‘Cross Validation: %d in %d‘ i n));
end
[mErr i] = min(Err);
%Compute the minimum one again using the optimal C and Sigma.
[alphaStar bStar SVIndex] = yxcSVMtrain(X Y C(i) kernel Sigma(i));
[YClassified Z Err(i)] = yxcSVMclassifer(Xtrain Xtrain Y alphaStar bStar kernel Sigma(i));
disp(sprintf(‘Error rate is %%%d with C = %d sigma = %d‘ mErr*100 C(i) Sigma(i)));
disp(sprintf(‘There are %d support vectors %d out of %d are wrongly classified‘ ...
length(SVIndex) mErr*length(Y) length(Y)));
yxcSVMplot(X Y SVIndex alphaStar bStar kernel Sigma(i) plotAxis);
title(sprintf(‘Isis-setosa(1) and Isis-versicolor(2) SV = %d Err = %%%d C = %d Sigma = %d‘ ...
length(SVIndex) mErr*100 C(i) Sigma(i)));
% Test all data on the Isis-setosa(1) and Isis-versicolor(2) data set.
[Y12 Z] = yxcSVMclassifer(Xtrain Xtest Y alphaStar bStar kernel Sigma(i));
Y12(find(Y12==1)) = 1;
Y12(find(Y12==-1)) = 2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Then train Isis-versicolor(2) and Isis-virginica(3) using grid search.
%
disp(‘.....................................................................‘)
X = irisData(51 : 150 3 : 4);
Y = irisData(51 : 150 5);
Y(find(Y==2)) = 1;
Y(find(Y==3)) = -1;
Xtrain = X;
disp(‘Training Isis-versicolor(2) and Isis-virginica(3) using grid search.‘)
disp(‘Please wait a while.‘);
for i = 1 : n
[alphaStar bStar SVIndex] = yxcSVMtrain(X Y C(i) kernel Sigma(i));
[YClassified Z Err(i)] = yxcSVMclassifer(Xtrain Xtrain
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2699 2007-04-04 10:23 三分类_svm_matlab\iris.data
文件 6455 2007-11-09 10:31 三分类_svm_matlab\irisSVM.m
文件 1905 2007-11-09 09:22 三分类_svm_matlab\yxcSVMclassifer.m
文件 1079 2007-11-09 09:22 三分类_svm_matlab\yxcSVMkernel.m
文件 2118 2007-11-09 09:30 三分类_svm_matlab\yxcSVMplot.m
文件 2415 2007-11-09 09:19 三分类_svm_matlab\yxcSVMtrain.m
目录 0 2009-08-03 21:57 三分类_svm_matlab
----------- --------- ---------- ----- ----
16671 7
- 上一篇:故障分类svm代码
- 下一篇:BP神经网络Matlab程序--绝对经典
相关资源
- BP神经网络Matlab程序--绝对经典
- 故障分类svm代码
- ICA原理及matlab实现
-
自制的基于MATLAB Simuli
nk的SVPWM模型 - matlab论文 线性回归问题
- 自相关功率谱的线谱提取
- matlab复杂网络及其零模型性质计算
- 雅可比矩阵matlab代码
- 基于Matlab的大学物理实验模拟
- 可以实时改变占空比的Pulse Generator
- omp算法matlab稀疏表示中用来求最优解
- 修正剑桥模型程序
- 浅水波方程 matlab实现 两种不同方法
- 基于matlab的jpeg编解码程序
- 阵列信号处理的理论和应用 matlab程序
- 高光谱遥感图像FuzzyMeansCluster算法-m
- 指纹识别matlab程序
- matlab实现模糊c均值聚类
- 空间离散点最小二乘直线拟合matlab代
- 读取BMP信息并显示的MATLAB程序
- 各种调制方式的matlab程序
- MATLAB灰度共生矩阵纹理特征提取
- 借助matlab实现粗糙集属性约简算法
- 一个零水印算法的matlab实现
- 滑模变结构控制MATLAB仿真基本理论与
- 基于粒子群算法机器人路径规划matl
- matlab6.5以上版本安装advisor2002补丁
- RVM相关向量机实现代码matlab源码
- MATLAB遗传算法215695
- wave_vorticity.m
评论
共有 条评论