📄 lssvm预测程序.m
字号:
%本程序是一个用LSSVM实现简单煤炭数据先拟合,再预测的例子%数据来源可参考吴海山的"煤炭需求量预测的支持向量机模型"一文%仿真结果比对请参考程序后面的注释%工具箱为 LS-SVMlab1.5aw ,可以在http://www.esat.kuleuven.ac.be/sista/lssvmlab上下载%---------------------------------------------------%以下问题请研友讨论:%(1)本人目前想用粒子群优化来优化sig2,gam,大家觉得可行性如何,附件中有一篇“Fast Bootstrap applied toLS-SVM for Long Term Prediction ",大家可共同研究 %(2)以上用的是单步递推预测,大家有没有做过直接多步预测。%(3)LSSVM调整的参数只有两个,从我的实验可以看出,gam的影响是比较小的,是否还有必要进行双参数优化%(4)LSSVM工具箱中有windowizeNARX以及预测函数predict,我用其实验的时候速度即慢,运行两次均死机,最后放弃,哪位用过请讨论。%(5)本人数学基础较差,对于LSSVM和SVR到底哪一个在函数预测上更好不置可否,请高人从理论上指点。文献上都说LSSVM稳健性及泛化能力强,速度快%本人实验结果是加噪声后预测能力明显下降,而且加噪声后受参数影响变大。%(6)RBF核函数到底比其它各种核函数好在哪里?能通俗点讲一下吗?% 2005/9/22 judyeking@163.com QQ:24444345%---------------------------------------------------%信号准备clc;clear all; close all;t=1980:1:2002;%1980到2002年的煤炭产量,用80-98作为训练数据,99-02为测试数据x=[61009.5 60583.8 64125.8 68713 74968.3 81603 86006 92799 99354 1.0343e+005 ... 1.0552e+005 1.1043e+005 1.1409e+005 1.2092e+005 1.2853e+005 1.3768e+005 1.4473e+005 1.3925e+005 1.2949e+005];%... % 1.2637e+005 1.2454e+005 1.2621e+005 1.3661e+005 ];% 99-02为测试数据 xtest=[1.2637e+005 1.2454e+005 1.2621e+005 1.3661e+005 ];%归一化MAX=max(x);MIN=min(x);x=(x-MIN)./(MAX-MIN);%-------------------------------------------------------------------------------%构造输入输出矩阵p=5;%embeded dimension,应该用CHAOS理论来求解,此处直接用了。x=x';Y_svm=x(p+1:end);for i=p:-1:1 X_svm(:,i)=x(p-i+1:end-i);end%---------------------------------------------------%用LSSVM模型进行训练gam = 10000;sig2 = 2;%---------------------------------------------------% gam low minimizing of the complexity of the model is emphasized,% for gam high, good fitting of the training data points is stressed.% large sig2 indicates a stronger smoothing. %---------------------------------------------------type = 'function estimation';% [alpha,b] = trainlssvm({X,Y,type,gam,sig2,'RBF_kernel'});% [alpha,b] = trainlssvm({X,Y,type,gam,sig2,'RBF_kernel','original'}); [alpha,b] = trainlssvm({X_svm,Y_svm,type,gam,sig2,'RBF_kernel','preprocess'}); %不知道上面三个命令有什么实质区别,反正只调用'original'误差极大,调用其它两个均可%---------------------------------------------------% % 用LSSVM模型进行预测%构造预测向量step_to_predict=4;%预测09-02年的值temp_matrix=x(end-p+1:end)';%---------------------------------------------------% 94.95,96,97,98---->99% 95,96,97,98,99---->00% 96,97,98,99,00---->01% 97,98,99,00,01---->02for i=1:1:step_to_predict Xt=temp_matrix;%先用94.95,96,97,98年的数据作为输入 Yt = simlssvm({X_svm,Y_svm,type,gam,sig2,'RBF_kernel','preprocess'},{alpha,b},Xt);% figure; plotlssvm({X,Y,type,gam,sig2,'RBF_kernel','preprocess'},{alpha,b}); temp_matrix=[temp_matrix(1,2:end) Yt ] ;endsvm_multi=(temp_matrix.*(MAX-MIN))+MIN;error=svm_multi(2:end)-xtest;err_percent=error./svm_multi(2:end);err=error*error';svm_multi(2:end)%因为最后矩阵里面是98,99,00,01,02后面的四个是预测值err_percenterr %------------------------------------------------------------------------------- %仿真结果 % gam = 10000;sig2 = 20; 1.2061 1.2860 1.3192 1.2939 %err_percent = -0.0477 0.0315 0.0433 -0.0558 error^2 = 1.3444e+008 % gam = 1000;sig2 = 2; %1.2051 1.2860 1.3187 1.2930 %-0.0486 0.0316 0.0429 -0.0566 error^2 = =1.3634e+008 % gam = 100;sig2 = 2; % 1.2013 1.2861 1.3165 1.2897 %-0.0519 0.0317 0.0413 -0.0592 error^2 = =1.4353e+008 % gam = 10;sig2 = 2; % 1.1991 1.2846 1.3124 1.28611 % -0.0539 0.0305 0.0383 -0.0622 error^2 = =1.4636e+008 % 从以上几组比对 可以看出,相同的sig2,gam 的变化对预测效果影响很小,相同的sig2,gam越大,误差平方和越小。误差百分比的水平也在一个水平上 % gam = 10;sig2 =0.2; 1.1497 1.2350 1.2024 1.1764 %err_percent =-0.0992 -0.0084 -0.0496 -0.1612 error^2 = = 5.2651e+008 % gam = 10;sig2 =0.8; 1.1742 1.2799 1.2721 1.2361 %err_percent = -0.0762 0.0270 0.0079 -0.1052 error^2 = = 2.6190e+008 % 从以上几组比对 可以看出,sig2的变化对预测误差平方和影响很大,相同的gam,sig2越大,误差平方和越大 %-------------------------------------------------------------------------------% 2005/9/22 10:06am judyeking@163.com QQ:24444345
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -