本文主要是介绍基于LS-SVM工具箱的多输入单…,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
clc ;
clear;
close all
%---------------------------------------------------
% 产生训练样本与测试样本
xn_train1 = 1:2:200;
xn_train2 = 1:1:100;
dn_train = xn_train1+2*xn_train2;
xn_test1 = 2:2:200;
xn_test2 = 1:2:200;
dn_test = xn_test1+2*xn_test2;
%---------------------------------------------------
% 参数设置 (由于lssvm中函数调用X,Y时,默认行是样本个数,列是自变量的个数【即如输入为单变量则列为1,3变量则列为3,所以要做转置)
% 注意看下
% d Dimension of the input vectors
% m Dimension of the output vectors
% N Number of training data
% Nt Number of test data
% X N×d matrix with the inputs of the training data
% Xt Nt×d matrix with the inputs of the test data
% Y N×m matrix with the outputs of the training data
% Yt Nt×m matrix with the outputs of the test data
% 输入:X(100*2),输出Y(100*1),Xt(100*2),Yt(100*1)
X = [xn_train1' xn_train2'];
Y = dn_train';
Xt =[xn_test1' xn_test2'];
Yt = dn_test';
type = 'function estimation';
kernel = 'RBF_kernel';
gam = 602572453.6492 ;
sig2 = 329.5513877868;
model = initlssvm(X,Y,type,gam,sig2,kernel);
%---------------------------------------------------
% 训练与测试
model = trainlssvm(model);
Yp = simlssvm(model,Xt);
%---------------------------------------------------
% 结果作图
plot(1:length(Yt),Yt,'r+:',1:length(Yp),Yp,'bo:')
title('+为真实值,o为预测值')
本文转载于(http://www.ilovematlab.cn/forum.php?mod=viewthread&tid=177076&highlight=),请尊重作者,支持原创。
这篇关于基于LS-SVM工具箱的多输入单…的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!