最近开始学习,支持向量机到底能不能做回归?能不能达到好的效果,真的很困惑,至少用libsvm没有达到很好的效果,但是漫天飞舞说的天花乱坠的效果非常好的文献是造假的么,很困惑,望高手指导一下,把我自己作的结果发在这看看,构造的函数模型来检验。
clear;clc;
%一元函数回归和预测,没问题
x1=(-1:0.1:1)';
y=-x1.^2;plot(x1,y,'ro');hold on;
model=svmtrain(y,x1,'-s 3 -t 2 -c 2.2 -g 2.8 -p 0.01');
[py,mse]=svmpredict(y,x1,model);
plot(x1,py,'b*');testx=[1.1 1.2 1.3]';testy=-testx.^2;
%testx=[-0.55 -0.65 -0.75]';testy=-testx.^2;取值在区间内效果比较好,这是我自己做的;
[pyt,mse]=svmpredict(testy,testx, model);%这是视频上的例子
clear;clc;
%一元函数回归和预测,参数寻优再预测,效果非常好
x1=(-1:0.1:1)';
y=-x1.^2;
plot(x1,y,'ro');hold on;
[bestmse,bestc,bestg] = SVMcgForRegress(y,x1,-10, 20, -10, 10);
cmd=['-s 3 -t 2',' -c ', num2str(bestc), ' -g ', num2str(bestg)];
model=svmtrain(y,x1,cmd);
[py,mse]=svmpredict(y,x1,model);
plot(x1,py,'b*');testx=[1.1 1.2 1.3]';testy=-testx.^2.+sin(testx);
[pyt,mse]=svmpredict(testy,testx, model);
clear;clc;
%一元函数回归和预测,参数寻优再预测,效果可以
x1=(-1:0.1:1)';
y=-x1.^2+3*sin(x1);
plot(x1,y,'ro');hold on;
[bestmse,bestc,bestg] = SVMcgForRegress(y,x1,-10, 20, -10, 5);
%cmd=['-s 3 -t 2',' -c ', num2str(bestc), ' -g ', num2str(bestg)];
model=svmtrain(y,x1,'-s 3 -t 2 -c 8 -g 0.5 -p 0.01');
[py,mse]=svmpredict(y,x1,model);
plot(x1,py,'b*');testx=[1.1 1.2 1.3]';testy=-testx.^2.+3*sin(testx);
%二元函数回归和预测,效果非常差
x1=(-1:0.1:1)';x2=(0:0.1:2)';x=[x1 x2];
y=-x1.^3+sin(x2);
[bestmse,bestc,bestg] = SVMcgForRegress(y,x,-10, 30, -10, 10,3,0.5,0.5);
cmd=['-s 3 -t 2',' -c ', num2str(bestc), ' -g ', num2str(bestg)];
model=svmtrain(y,x,cmd);
[py,mse]=svmpredict(y,x, model);
testx1=[1.1 1.2 1.3]';testx2=[2 2.1 2.2]';testy=-testx1.^3+sin(testx2);
[pyt,mse]=svmpredict(testy,[testx1,testx2], model);
p=((pyt-testy)./testy)';