支持向量机回归算法matlab,支持向量机到底能不能做回归

最近开始学习,支持向量机到底能不能做回归?能不能达到好的效果,真的很困惑,至少用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)';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值