matlab libsvm svr,libsvm的SVR程序

之前因为不想装VC6所以就一直撇弃libsvm,而用说过的一个svm工具箱,可清明时节写论文,发现那个程序能拟合,但不能做预测,无奈,求索,最终得到高人的指点,而终于下载了VC6,装了libsvm。弱弱的说一句,这电脑快崩了,哎。。。。

言归正传。

第一次是用ABC-woods大哥发我的libsvm-mat-2.89-3-[farutoUltimateVersion1.0].rar,可加载完成后,发现程序运行不起来,一直说没有mapminmax这个函数,这是归一化的函数,但怎么会没有??!!后来发现原来是matlab版本太低,2010版本是自带这个函数的,但7.0是没有的,于是网上找到了这个函数,并放到工具箱内,终于ok,搞出结果:

程序1:(仍旧用那个粮食产量的例子)

%本程序是ABC-woods写的,工具箱运用的是libsvm-mat-2.89-3-[farutoUltimateVersion1.0].rar

%% 整理数据

close all;clear;clc;

%数据

waste=importdata('E:\crop.txt');

%% classify the sample data and test data

kkt=1:15;%randperm(30);

traint=kkt(1:12);textt=kkt(1:15);

%训练集 输入 输出

data_train=waste(traint,:); data_test=waste(textt,:);

% Train data

b = size(data_train,2);

X=data_train(:,1:(b-1)); Y=data_train(:,b);

% % Text data

b = size(data_test,2);

%测试集 输入 输出

XT=data_test(:,1:(b-1));

YT=data_test(:,b);

YT

figure(1);

plot(YT,'o-');legend('original');

grid on;

% whos YT;

% % Standing for the data

[X_scale,XT_scale] = scaleForSVM(X,XT,0,1);

X_scale;

XT_scale;

% without standing for the

data % X_scale=X;

% XT_scale=XT;

%reggressive

%构建model

[bestmse,bestc,bestg] = SVMcgForRegress(Y,X_scale,-8,8,-8,8)

cmd = ['-c ',num2str(bestc),' -g ',num2str(bestg),' -s 3 -t 1 -r

2.5 -d 2 -p 0.9 -e 1'];

model = svmtrain(Y,X_scale,cmd);

%做预测

[Ypre,mse] = svmpredict(YT,XT_scale,model);

Ypre

%画图

figure(1);

hold on;

plot(Ypre,'r*-');

z=(Ypre-YT);

figure (1)

z1=Ypre+0.2;z2=Ypre-0.2;

plot(z1,'g -');

bar(z, 'DisplayName', 'z', 'YDataSource', 'z'); figure(gcf);

plot(z2,'g -');

legend('Actual','Prediction','Predict+ε','Error','Predict-ε');

结果:

a4c26d1e5885305701be709a3d33442f.png

模拟预测还算客观。

以为这就ok,但论文的股票价格预测精度要求比较高,但这个程序is not

satisfied,于是只好僵滞,直到几天年,一位网上朋友重新提了这个,才搞定,这个程序的工具箱其实跟上面那个是差不多的,都是faruto编写的,只是版本升级了下,是libsvm-mat-2.89-3[FarutoUltimate3.0Mcode].rar,需要的朋友我可以发给他。邮箱jiemin1217@126.com

顺便把程序粘贴如下:

function

y=x(cc)

clc

factor=load('d:\factor.txt');

result=load('d:\result.txt');

b=size(factor);

n=b(1,1)

train_x=factor(1:n-3,:);

train_y=result(1:n-3,:);

test_x=factor(1:n,:);

test_y=result(1:n,:);

Method_option.plotOriginal = 0;

Method_option.xscale = 1;

Method_option.yscale = 1;

Method_option.plotScale = 0;

Method_option.pca = 0;

Method_option.type = 1;

[predict_Y,mse,r] =

SVR(train_y,train_x,test_y,test_x,Method_option);

% predict_Y{1,1,1}

disp('1:')

predict_Y{1,2,1}

% Method_option.type = 2;

% [predict_Y,mse,r] =

SVR(train_y,train_x,test_y,test_x,Method_option);

% disp('2:')

% predict_Y{1,2,1}

% %

% Method_option.type = 3;

% [predict_Y,mse,r] =

SVR(train_y,train_x,test_y,test_x,Method_option);

% disp('3:')

% predict_Y{1,2,1}

% %

% %

% Method_option.type = 5;

% [predict_Y,mse,r] =

SVR(train_y,train_x,test_y,test_x,Method_option);

% disp('5:')

% predict_Y{1,2,1}

结果:

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值