-
大小: 218KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2024-02-05
- 語(yǔ)言: Matlab
- 標(biāo)簽:
資源簡(jiǎn)介
matlab關(guān)于SVM的回歸預(yù)測(cè)分析(上證指數(shù)開(kāi)盤指數(shù)預(yù)測(cè))相關(guān)代碼

代碼片段和文件信息
%%?Matlab神經(jīng)網(wǎng)絡(luò)43個(gè)案例分析
%?基于SVM的回歸預(yù)測(cè)分析——上證指數(shù)開(kāi)盤指數(shù)預(yù)測(cè)
%?by?李洋(faruto)
%?http://www.matlabsky.com
%?Email:faruto@163.com
%?http://weibo.com/faruto?
%?http://blog.sina.com.cn/faruto
%?2013.01.01
%%?清空環(huán)境變量
function?chapter_sh
tic;
close?all;
clear;
clc;
format?compact;
%%?數(shù)據(jù)的提取和預(yù)處理
%?載入測(cè)試數(shù)據(jù)上證指數(shù)(1990.12.19-2009.08.19)
%?數(shù)據(jù)是一個(gè)4579*6的double型的矩陣每一行表示每一天的上證指數(shù)
%?6列分別表示當(dāng)天上證指數(shù)的開(kāi)盤指數(shù)指數(shù)最高值指數(shù)最低值收盤指數(shù)當(dāng)日交易量當(dāng)日交易額.
load?chapter_sh.mat;
%?提取數(shù)據(jù)
[mn]?=?size(sh);
ts?=?sh(2:m1);
tsx?=?sh(1:m-1:);
%?畫出原始上證指數(shù)的每日開(kāi)盤數(shù)
figure;
plot(ts‘LineWidth‘2);
title(‘上證指數(shù)的每日開(kāi)盤數(shù)(1990.12.20-2009.08.19)‘‘FontSize‘12);
xlabel(‘交易日天數(shù)(1990.12.19-2009.08.19)‘‘FontSize‘12);
ylabel(‘開(kāi)盤數(shù)‘‘FontSize‘12);
grid?on;
%?數(shù)據(jù)預(yù)處理將原始數(shù)據(jù)進(jìn)行歸一化
ts?=?ts‘;
tsx?=?tsx‘;
%?mapminmax為matlab自帶的映射函數(shù)
%?對(duì)ts進(jìn)行歸一化
[TSTSps]?=?mapminmax(ts12);
%?畫出原始上證指數(shù)的每日開(kāi)盤數(shù)歸一化后的圖像
figure;
plot(TS‘LineWidth‘2);
title(‘原始上證指數(shù)的每日開(kāi)盤數(shù)歸一化后的圖像‘‘FontSize‘12);
xlabel(‘交易日天數(shù)(1990.12.19-2009.08.19)‘‘FontSize‘12);
ylabel(‘歸一化后的開(kāi)盤數(shù)‘‘FontSize‘12);
grid?on;
%?對(duì)TS進(jìn)行轉(zhuǎn)置以符合libsvm工具箱的數(shù)據(jù)格式要求
TS?=?TS‘;
%?mapminmax為matlab自帶的映射函數(shù)
%?對(duì)tsx進(jìn)行歸一化
[TSXTSXps]?=?mapminmax(tsx12);
%?對(duì)TSX進(jìn)行轉(zhuǎn)置以符合libsvm工具箱的數(shù)據(jù)格式要求
TSX?=?TSX‘;
%%?選擇回歸預(yù)測(cè)分析最佳的SVM參數(shù)c&g
%?首先進(jìn)行粗略選擇:?
[bestmsebestcbestg]?=?SVMcgForRegress(TSTSX-88-88);
%?打印粗略選擇結(jié)果
disp(‘打印粗略選擇結(jié)果‘);
str?=?sprintf(?‘Best?Cross?Validation?MSE?=?%g?Best?c?=?%g?Best?g?=?%g‘bestmsebestcbestg);
disp(str);
%?根據(jù)粗略選擇的結(jié)果圖再進(jìn)行精細(xì)選擇:?
[bestmsebestcbestg]?=?SVMcgForRegress(TSTSX-44-4430.50.50.05);
%?打印精細(xì)選擇結(jié)果
disp(‘打印精細(xì)選擇結(jié)果‘);
str?=?sprintf(?‘Best?Cross?Validation?MSE?=?%g?Best?c?=?%g?Best?g?=?%g‘bestmsebestcbestg);
disp(str);
%%?利用回歸預(yù)測(cè)分析最佳的參數(shù)進(jìn)行SVM網(wǎng)絡(luò)訓(xùn)練
cmd?=?[‘-c?‘?num2str(bestc)?‘?-g?‘?num2str(bestg)??‘?-s?3?-p?0.01‘];
model?=?svmtrain(TSTSXcmd);
%%?SVM網(wǎng)絡(luò)回歸預(yù)測(cè)
[predictmse]?=?svmpredict(TSTSXmodel);
predict?=?mapminmax(‘reverse‘predict‘TSps);
predict?=?predict‘;
%?打印回歸結(jié)果
str?=?sprintf(?‘均方誤差?MSE?=?%g?相關(guān)系數(shù)?R?=?%g%%‘mse(2)mse(3)*100);
disp(str);
%%?結(jié)果分析
figure;
hold?on;
plot(ts‘-o‘);
plot(predict‘r-^‘);
legend(‘原始數(shù)據(jù)‘‘回歸預(yù)測(cè)數(shù)據(jù)‘);
hold?off;
title(‘原始數(shù)據(jù)和回歸預(yù)測(cè)數(shù)據(jù)對(duì)比‘‘FontSize‘12);
xlabel(‘交易日天數(shù)(1990.12.19-2009.08.19)‘‘FontSize‘12);
ylabel(‘開(kāi)盤數(shù)‘‘FontSize‘12);
grid?on;
figure;
error?=?predict?-?ts‘;
plot(error‘rd‘);
title(‘誤差圖(predicted?data?-?original?data)‘‘FontSize‘12);
xlabel(‘交易日天數(shù)(1990.12.19-2009.08.19)‘‘FontSize‘12);
ylabel(‘誤差量‘‘FontSize‘12);
grid?on;
figure;
error?=?(predict?-?ts‘)./ts‘;
plot(error‘rd‘);
title(‘相對(duì)誤差圖(predicted?data?-?original?data)/original?data‘‘FontSize‘12);
xlabel(‘交易日天數(shù)(1990.12.19-2009.08.19)‘‘FontSize‘12);
ylabel(‘相對(duì)誤差量‘‘FontSize‘12);
grid?on;
snapnow;
toc;
%%?子函數(shù)?SVMcgForRegress.m
function?[msebestcbestg]?=?SVMcgForRegress(train_labeltraincmincmaxgmingmaxvcstepgstepmsestep)
%SVMcg?cross?validation?by?faruto
%
%?by?faruto
%Email:patrick.lee@foxmail.com?QQ:516667408?http://blog.sina.com.cn/faruto?BNU
%last?modified?2010.01.17
%Super?Moderator?@?www.ilovematlab.cn
%?若轉(zhuǎn)載請(qǐng)注明:
%?faruto?and?liyang??LIBSVM-farutoUltimat
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????5529??2013-08-18?10:59??chapter16\chapter_sh.m
?????文件?????219976??2010-01-30?18:39??chapter16\chapter_sh.mat
?????文件??????24872??2013-08-18?11:01??chapter16\html\chapter_sh.html
?????文件???????3998??2013-08-18?11:01??chapter16\html\chapter_sh.png
?????文件???????9331??2013-08-18?10:59??chapter16\html\chapter_sh_01.png
?????文件??????10025??2013-08-18?10:59??chapter16\html\chapter_sh_02.png
?????文件??????17498??2013-08-18?11:01??chapter16\html\chapter_sh_03.png
?????文件??????18915??2013-08-18?11:01??chapter16\html\chapter_sh_04.png
?????文件??????22389??2013-08-18?11:01??chapter16\html\chapter_sh_05.png
?????文件??????17509??2013-08-18?11:01??chapter16\html\chapter_sh_06.png
?????文件??????12441??2013-08-18?11:01??chapter16\html\chapter_sh_07.png
?????文件??????12113??2013-08-18?11:01??chapter16\html\chapter_sh_08.png
?????文件??????10681??2013-08-18?11:01??chapter16\html\chapter_sh_09.png
?????目錄??????????0??2013-08-18?11:01??chapter16\html
?????目錄??????????0??2013-08-18?10:59??chapter16
-----------?---------??----------?-----??----
???????????????385277????????????????????15
評(píng)論
共有 條評(píng)論