|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
小弟初学svm,只是硬性的套用,请高手帮忙分析下下列程序
clc
clear
close all
%---------------------------------------------------
% 产生训练样本与测试样本,每一列为一个样本
n1 = [74.2500 69.5000 79.5000 80.5000 84.2500 85.7500 83.5000 82.5000 80.7500 86.0000 89.7500 88.7500
65.5000 67.5000 71.5000 73.5000 72.0000 85.0000 75.7500 80.7500 79.7500 77.2500 88.5000 90.7500
75.7500 68.0000 78.0000 75.2500 73.0000 80.7500 82.5000 81.0000 81.0000 83.0000 91.7500 89.0000
70.0000 69.2500 79.2500 74.7500 84.0000 85.2500 83.7500 79.5000 81.0000 84.7500 89.5000 92.2500
64.5000 70.7500 65.5000 65.7500 84.5000 56.7500 71.7500 87.0000 80.5000 74.5000 89.7500 89.5000
54.7500 67.0000 76.0000 72.2500 76.5000 76.2500 85.5000 80.7500 84.7500 80.5000 88.7500 91.0000
72.0000 69.0000 70.5000 74.5000 73.7500 75.0000 77.7500 77.0000 78.0000 80.2500 91.7500 88.7500
62.5000 58.2500 78.7500 57.7500 68.2500 84.5000 87.7500 72.0000 82.0000 83.2500 91.0000 87.5000
72.0000 67.5000 78.0000 74.7500 73.7500 82.7500 82.7500 75.7500 81.2500 82.0000 89.7500 89.2500
68.2500 70.5000 80.2500 73.0000 74.5000 66.0000 82.5000 79.7500 87.0000 81.0000 87.2500 90.5000
67.5000 68.2500 76.0000 83.0000 74.2500 83.7500 75.0000 82.5000 81.5000 81.0000 89.0000 90.0000
83.2500 68.2500 82.7500 76.0000 75.0000 82.2500 79.5000 75.5000 81.2500 81.7500 88.7500 90.5000
84.5000 69.2500 77.7500 77.0000 74.0000 82.0000 74.2500 77.2500 79.7500 79.7500 88.0000 88.7500
54.7500 56.7500 76.0000 73.0000 72.7500 87.5000 84.7500 82.0000 80.0000 79.0000 89.2500 90.0000
76.0000 70.5000 74.7500 76.0000 76.0000 88.5000 88.2500 82.0000 80.0000 79.2500 89.2500 90.5000
67.5000 68.2500 54.5000 76.2500 73.0000 76.0000 82.5000 84.5000 64.7500 81.2500 90.2500 90.5000];
x1 = [1*ones(1,2),2*ones(1,3),3*ones(1,5),4*ones(1,2)]; % 特别注意:这里的目标与神经网络不同
n2 = [ 75.0000 78.2500 89.7500
73.0000 80.7500 90.7500
73.5000 84.5000 87.5000
75.0000 83.0000 89.7500
75.5000 73.0000 89.0000
73.0000 80.5000 90.2500
76.5000 82.7500 89.7500
62.2500 78.2500 87.5000
75.5000 80.7500 89.0000
74.2500 86.0000 90.5000
75.5000 79.2500 90.5000
76.0000 78.0000 90.2500
72.5000 78.5000 91.5000
81.7500 82.0000 88.7500
74.0000 84.2500 91.5000
74.2500 80.5000 88.7500];
x2 = [2*ones(1,1),3*ones(1,1),4*ones(1,1)]; % 特别注意:这里的目标与神经网络不同
xn_train = n1; % 训练样本
dn_train = x1; % 训练目标
xn_test = n2; % 测试样本
dn_test = x2; % 测试目标
%---------------------------------------------------
% 参数设置
X = xn_train';
Y = dn_train';
Xt = xn_test';
Yt = dn_test';
type = 'c';
kernel_type = 'RBF_kernel';
gam =2 ;
sig2 =2;
preprocess = 'preprocess';
codefct = 'code_OneVsAll';
[Yc,codebook,old_codebook] = code(Y,codefct)
[gam,sig2] = tunelssvm({X,Yc,type,gam,sig2,kernel_type,preprocess});
[alpha,b] = trainlssvm({X,Yc,type,gam,sig2,kernel_type,preprocess}); % 训练
Yd0 = simlssvm({X,Yc,type,gam,sig2,kernel_type,preprocess},{alpha,b},Xt); % 分类
得出参数后进行样本测试
Yd1 = dn_test';
Yd2 = code(Yd1,old_codebook,[],codebook);
Xt=[73.5 73 76 73.5 71.5 70.75 74.25 73.75 75.25 74.5 75.25 71.5 71.5 74.75 74.75 74.5
84 79.5 81.5 85 81.75 70.75 83.25 77.5 83 78.5 83.5 80.25 82 85 83 81.75
87.25 89.75 92.75 91.25 88 89.25 87.5 88.5 89 91.25 91.5 88.25 90 91 86.75 86.75];
type = 'c';
kernel_type = 'RBF_kernel';
gam = 4.8841 ;
sig2 = 4.1852;
preprocess = 'preprocess';
codefct = 'code_OneVsAll';
[Yc,codebook,old_codebook] = code(Y,codefct);
Yd2 = simlssvm({X,Yc,type,gam,sig2,kernel_type,preprocess},{alpha,b},Xt); % 分类
plotlssvm({X,Yc,type,gam,sig2,kernel_type,preprocess},{alpha,b})
出来的结果是
m....Start Plotting...m....Warning: Simulation over the input space results in only one class...
> In plotlssvm at 132
Warning: only first dimension is plotted, for multiclass classification use categorical representation, ev. combined with a coding technique.
> In plotlssvm at 153
finished
请问 是我的数据不对导致的分级只出现一级。。。我仔细看了 源程序的132和153行 可是研究很长时间 没看懂 (zz)是什么 摆摊高手了。。。谢谢 |
|