我用libsvm-3.1-[FarutoUltimate3.1Mcode]做回归,因为是新手,做了之后误差很大,不知哪里出了问题,请各位大侠指教。
以下是程序:
close all;
clear;
clc;
format compact;
%%
% 生成待回归的数据
xa = (-1:0.1:1)';
xb=(-1:0.1:1)';
x=[xa,xb];
y = -xa.^2+6*xb;
[bestacc,bestc,bestg]=SVMcgForRegress(y,x,-10,10,-10,10)
%先运行上面步骤,得出c,g后,手动输入模型中,然后继续运行
% 建模回归模型
model = svmtrain(y,x,'-s 3 -t 2 -c 1024 -g 0.0825 -p 0.01');
% 利用建立的模型看其在训练集合上的回归效果
[py,mse] = svmpredict(y,x,model);
%看看训练集的回归误差
b=(py-y)./y*100;
a=[x,y,py,py-y,b]
%建立训练集
x1=(3:0.1:5)';
x2=(5:0.1:7)';
y1= -x1.^2+6*x2;
[py1,ms1] = svmpredict(y1,x1,model);
%看看测试误差
b1=(py1-y1)./y1*100;
c=[x1,x2,y1,py1,py1-y1,b1]
下面是结果:
bestacc =
1.5378e-04
bestc =
1024
bestg =
0.0825
>> % 建模回归模型
model = svmtrain(y,x,'-s 3 -t 2 -c 1024 -g 0.0825 -p 0.01');
% 利用建立的模型看其在训练集合上的回归效果
[py,mse] = svmpredict(y,x,model);
%看看训练集的回归误差
b=(py-y)./y*100;
a=[x,y,py,py-y,b]
%建立训练集
x1=(3:0.1:5)';
x2=(5:0.1:7)';
y1= -x1.^2+6*x2;
[py1,ms1] = svmpredict(y1,x1,model);
%看看测试误差
b1=(py1-y1)./y1*100;
c=[x1,x2,y1,py1,py1-y1,b1]
Mean squared error = 5.72249e-05 (regression)
Squared correlation coefficient = 0.999996 (regression)
a =
-1.0000 -1.0000 -7.0000 -6.9894 0.0106 -0.1521
-0.9000 -0.9000 -6.2100 -6.2147 -0.0047 0.0757
-0.8000 -0.8000 -5.4400 -5.4503 -0.0103 0.1890
-0.7000 -0.7000 -4.6900 -4.6996 -0.0096 0.2050
-0.6000 -0.6000 -3.9600 -3.9655 -0.0055 0.1399
-0.5000 -0.5000 -3.2500 -3.2503 -0.0003 0.0078
-0.4000 -0.4000 -2.5600 -2.5553 0.0047 -0.1830
-0.3000 -0.3000 -1.8900 -1.8817 0.0083 -0.4379
-0.2000 -0.2000 -1.2400 -1.2300 0.0100 -0.8093
-0.1000 -0.1000 -0.6100 -0.6001 0.0099 -1.6213
0 0 0 0.0081 0.0081 Inf
0.1000 0.1000 0.5900 0.5951 0.0051 0.8674
0.2000 0.2000 1.1600 1.1616 0.0016 0.1341
0.3000 0.3000 1.7100 1.7080 -0.0020 -0.1161
0.4000 0.4000 2.2400 2.2350 -0.0050 -0.2222
0.5000 0.5000 2.7500 2.7429 -0.0071 -0.2568
0.6000 0.6000 3.2400 3.2319 -0.0081 -0.2502
0.7000 0.7000 3.7100 3.7017 -0.0083 -0.2233
0.8000 0.8000 4.1600 4.1519 -0.0081 -0.1944
0.9000 0.9000 4.5900 4.5816 -0.0084 -0.1821
1.0000 1.0000 5.0000 4.9897 -0.0103 -0.2059
Mean squared error = 311.323 (regression)
Squared correlation coefficient = 0.966799 (regression)
c =
3.0000 5.0000 21.0000 3.4477 -17.5523 -83.5824
3.1000 5.1000 20.9900 3.3541 -17.6359 -84.0203
3.2000 5.2000 20.9600 3.2494 -17.7106 -84.4971
3.3000 5.3000 20.9100 3.1341 -17.7759 -85.0117
3.4000 5.4000 20.8400 3.0087 -17.8313 -85.5628
3.5000 5.5000 20.7500 2.8740 -17.8760 -86.1495
3.6000 5.6000 20.6400 2.7305 -17.9095 -86.7706
3.7000 5.7000 20.5100 2.5791 -17.9309 -87.4251
3.8000 5.8000 20.3600 2.4204 -17.9396 -88.1121
3.9000 5.9000 20.1900 2.2551 -17.9349 -88.8306
4.0000 6.0000 20.0000 2.0840 -17.9160 -89.5800
4.1000 6.1000 19.7900 1.9079 -17.8821 -90.3594
4.2000 6.2000 19.5600 1.7275 -17.8325 -91.1683
4.3000 6.3000 19.3100 1.5435 -17.7665 -92.0065
4.4000 6.4000 19.0400 1.3568 -17.6832 -92.8737
4.5000 6.5000 18.7500 1.1681 -17.5819 -93.7699
4.6000 6.6000 18.4400 0.9781 -17.4619 -94.6956
4.7000 6.7000 18.1100 0.7876 -17.3224 -95.6512
4.8000 6.8000 17.7600 0.5971 -17.1629 -96.6380
4.9000 6.9000 17.3900 0.4074 -16.9826 -97.6573
5.0000 7.0000 17.0000 0.2191 -16.7809 -98.7112
>>
截图00.gif (272.74 KB, 下载次数: 4)
2015-6-1 19:45 上传