?? regression_ls_svmlab.m
字號:
% 支持向量機用于函數擬合 - 必須選擇最優參數 gam,sig2% 工具箱:LS_SVMlab% 使用平臺:Matlab6.5% 作者:陸振波,海軍工程大學% 歡迎同行來信交流與合作,更多文章與程序下載請訪問我的個人主頁% 電子郵件:luzhenbo@yahoo.com.cn% 個人主頁:http://luzhenbo.88uu.com.cnclcclearclose all%---------------------------------------------------% 產生訓練樣本與測試樣本n1 = 1:2:200;x1 = sin(n1*0.1);n2 = 2:2:200;x2 = sin(n2*0.1);xn_train = n1; % 訓練樣本,每一列為一個樣本dn_train = x1; % 訓練目標,行向量xn_test = n2; % 測試樣本,每一列為一個樣本dn_test = x2; % 測試目標,行向量%---------------------------------------------------% 參數設置X = xn_train';Y = dn_train';Xt = xn_test';Yt = dn_test';type = 'f';kernel = 'RBF_kernel';gam = 100; % Regularization parametersig2 = 0.01; % Kernel parameter (bandwidth in the case of the 'RBF_kernel'model = initlssvm(X,Y,type,gam,sig2,kernel); % 模型初始化%---------------------------------------------------% 交叉驗證優化參數%costfun = 'rcrossvalidate';%costfun_args = {X,Y,10};%optfun = 'gridsearch';%model = tunelssvm(model,[],optfun,{},costfun,costfun_args); % 模型參數優化 %---------------------------------------------------% 訓練與測試model = trainlssvm(model); % 訓練 Yd = simlssvm(model,Xt); % 回歸%---------------------------------------------------% 結果作圖plot(1:length(Yt),Yt,'r+:',1:length(Yd),Yd,'bo:')title('+為真實值,o為預測值')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -