%% 闲鱼号/面包多:深度学习与智能算法
function [model, b, X, Y] = trainlssvm(model, X, Y)
%% 训练模型
% >> model = trainlssvm(model)
% type can be 'classifier' or 'function estimation' (these strings
% can be abbreviated into 'c' or 'f', respectively). X and Y are
% matrices holding the training input and output data. The i-th
% data point is represented by the i-th row X(i,:) and Y(i,:). gam
% is the regularization parameter: for gam low minimizing of the
% complexity of the model is emphasized, for gam high, good fitting
% of the training data points is stressed. kernel_par is the
% parameter of the kernel; in the common case of an RBF kernel, a
% large sig2 indicates a stronger smoothing. The kernel_type
% indicates the function that is called to compute the kernel value
% (by default RBF_kernel). Other kernels can be used for example:
%
% The kernel parameter(s) are passed as a row vector, in the case
% no kernel parameter is needed, pass the empty vector!
%
% The training can either be proceeded by the preprocessing
% function ('preprocess') (by default) or not ('original'). The
% training calls the preprocessing (prelssvm, postlssvm) and the
% encoder (codelssvm) if appropiate.
%
% In the remainder of the text, the content of the cell determining
% the LS-SVM is given by {X,Y, type, gam, sig2}. However, the
% additional arguments in this cell can always be added in the
% calls.
%
% If one uses the object oriented interface (see also A.3.14), the training is done by
%
% >> model = trainlssvm(model)
% >> model = trainlssvm(model, X, Y)
%
% The status of the model checks whether a retraining is
% needed. The extra arguments X, Y allow to re-initialize the model
% with this new training data as long as its dimensions are the
% same as the old initiation.
%
% The training implementation:
%
% * The Matlab implementation: a straightforward implementation
% based on the matrix division '\' (lssvmMATLAB.m).
%
%
% This implementation allows to train a multidimensional output
% problem. If each output uses the same kernel type, kernel
% parameters and regularization parameter, this is
% straightforward. If not so, one can specify the different types
% and/or parameters as a row vector in the appropriate
% argument. Each dimension will be trained with the corresponding
% column in this vector.
% model = trainlssvm(model)
% model : Trained object oriented representation of the LS-SVM model
% model : Object oriented representation of the LS-SVM model
% X(*) : N x d matrix with the inputs of the training data
% Y(*) : N x 1 vector with the outputs of the training data
% type(*) : 'function estimation' ('f') or 'classifier' ('c')
% gam(*) : Regularization parameter
% sig2(*) : Kernel parameter (bandwidth in the case of the 'RBF_kernel')
% kernel(*) : Kernel type (by default 'RBF_kernel')
% preprocess(*) : 'preprocess'(*) or 'original'
%% 初始化模型
if iscell(model)
model = initlssvm(model{:});
end
%% 判断模型训练状态
if model.status(1) == 't'
if (nargout > 1)
X = model.xtrain;
Y = model.ytrain;
b = model.b;
model = model.alpha;
end
return
end
%% 控制输入
if ~((strcmp(model.kernel_type, 'RBF_kernel') && length(model.kernel_pars) >= 1) ||...
(strcmp(model.kernel_type, 'lin_kernel') && length(model.kernel_pars) >= 0) ||...
(strcmp(model.kernel_type, 'MLP_kernel') && length(model.kernel_pars) >= 2) ||...
(strcmp(model.kernel_type, 'poly_kernel') && length(model.kernel_pars) >= 1))
elseif (model.steps <= 0)
error('steps must be larger then 0');
elseif (model.gam <= 0)
error('gamma must be larger then 0');
elseif or(model.x_dim <= 0, model.y_dim <= 0)
error('dimension of datapoints must be larger than 0');
end
%% 编码(分类才需要)
if model.code(1) == 'c'
model = codelssvm(model);
end
%% 赋值
try
if model.prestatus(1)=='c'
changed = 1;
else
changed = 0;
end
catch
changed = 0;
end
if model.preprocess(1) == 'p' && changed
model = prelssvm(model);
elseif model.preprocess(1) == 'o' && changed
model = postlssvm(model);
end
%% 计时开始
tic;
%% 执行方式
if size(model.gam, 1) > 1
model.implementation = 'MATLAB';
end
%% 递归调用输出维度预测
if model.y_dim > 1
if (length(model.kernel_pars) == model.y_dim || size(model.gam, ...
2) == model.y_dim || numel(model.kernel_type, 2) == model.y_dim)
model = trainmultidimoutput(model);
if (nargout > 1)
X = model.xtrain;
Y = model.ytrain;
b = model.b;
model = model.alpha;
else
model.duration = toc;
model.status = 'trained';
end
return
end
end
%%
model = lssvmMATLAB(model);
if (nargout > 1)
X = model.xtrain;
Y = model.ytrain;
b = model.b;
model = model.alpha;
else
model.duration = toc;
model.status = 'trained';
end
%% 训练多输出模型
function model = trainmultidimoutput(model)
%% 初始化权重
model.alpha = zeros(model.nb_data, model.y_dim);
model.b = zeros(1, model.y_dim);
for d = 1 : model.y_dim
try
gam = model.gam(:, d);
catch
gam = model.gam(:);
end
try
sig2 = model.kernel_pars(:, d);
catch
sig2 = model.kernel_pars(:);
end
try
kernel = model.kernel_type{d};
catch
kernel=model.kernel_type;
end
[model.alpha(:, d), model.b(d)] = trainlssvm({model.xtrain, model.ytrain(:, d), ...
model.type, gam, sig2, kernel, 'original'});
end
%% 输出
if (nargout > 1)
model = model.alpha;
else
model.duration = toc;
model.status = 'trained';
end
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1.Matlab实现LSSVM-ABKDE基于最小二乘支持向量机结合自适应带宽核函数密度估计的多变量回归区间预测(完整源码和数据) 2.LSSVM-ABKDE基于最小二乘支持向量机结合自适应带宽核函数密度估计的多变量回归预测(点预测+概率预测+核密度估计) Matlab语言 3.多变量单输出,包括点预测+概率预测+核密度估计曲线,MatlabR2021a及以上版本运行,提供多种置信区间!评价指标包括R2、MAE、RMSE、MAPE、区间覆盖率picp、区间平均宽度百分比pinaw等。 4.算法新颖,对固定带宽核函数进行了改进。 5.直接替换Excel数据即可用,注释清晰,适合新手小白,直接运行main文件一键出图。 6.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 7.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。 8.作者介绍:某大厂资深算法工程师,从事Matlab、Python算法仿真工作8年;擅长智能优化算法、神经网络预测、信号处理、元胞自动机等多种领域的算法仿真实验,更多仿真源码、数据集定制私信+。
资源推荐
资源详情
资源评论
收起资源包目录
区间预测:LSSVM-ABKDE.zip (24个子文件)
LSSVM-ABKDE
QuantSol_FUN.m 124B
LSSVM_ToolBox
trainlssvm.m 6KB
code_MOC.m 374B
lssvmMATLAB.m 1KB
initlssvm.m 2KB
postlssvm.m 4KB
code_OneVsAll.m 219B
prelssvm.m 6KB
kernel_matrix.m 3KB
code_OneVsOne.m 413B
codedist_hamming.m 647B
simlssvm.m 4KB
code.m 3KB
PINAW_FUN.m 165B
PlotProbability.m 1KB
CRPS_FUN.m 570B
main.m 5KB
数据集.xlsx 39KB
PlotKernelDensity.m 2KB
CWC_FUN.m 391B
ABKDE.m 6KB
PICP_FUN.m 412B
PlotError.m 1KB
LSSVM-ABKDE.zip 58KB
共 24 条
- 1
资源评论
- 王康德2024-02-05资源简直太好了,完美解决了当下遇到的难题,这样的资源很难不支持~
- wangxiaozhen1232024-04-02感谢资源主分享的资源解决了我当下的问题,非常有用的资源。
- smoking_dingzhen2024-06-18发现一个宝藏资源,资源有很高的参考价值,赶紧学起来~
- 胡贝贝2024-03-30资源太好了,解决了我当下遇到的难题,抱紧大佬的大腿~
- m0_453129882024-02-25这个资源内容超赞,对我来说很有价值,很实用,感谢大佬分享~
机器学习之心
- 粉丝: 2w+
- 资源: 1031
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功