【MATLAB第61期】基于MATLAB的GMM高斯混合模型回歸數(shù)據(jù)預(yù)測
- 高斯混合模型GMM廣泛應(yīng)用于數(shù)據(jù)挖掘、模式識別、機(jī)器學(xué)習(xí)和統(tǒng)計(jì)分析。其中,它們的參數(shù)通常由最大似然和EM算法確定。
- 關(guān)鍵思想是使用高斯混合模型對數(shù)據(jù)(包括輸入和輸出)的聯(lián)合概率密度函數(shù)進(jìn)行建模。
- 文獻(xiàn)參考:https://doi.org/10.1016/j.specom.2012.06.005。
- 使用工具箱netlab。
一、效果展示
文章來源:http://www.zghlxwxcb.cn/news/detail-616633.html
二、代碼展示
1.數(shù)據(jù)(7輸入1輸出)
%% 清空環(huán)境變量
warning off % 關(guān)閉報(bào)警信息
close all % 關(guān)閉開啟的圖窗
clear % 清空變量
clc % 清空命令行
%% 導(dǎo)入數(shù)據(jù)
res = xlsread('數(shù)據(jù)集.xlsx');
%% 劃分訓(xùn)練集和測試集
temp = randperm(103);
P_train = res(temp(1: 80), 1: 7)';
T_train = res(temp(1: 80), 8)';
M = size(P_train, 2);
P_test = res(temp(81: end), 1: 7)';
T_test = res(temp(81: end), 8)';
N = size(P_test, 2);
%% 數(shù)據(jù)歸一化
[p_train, ps_input] = mapminmax(P_train, 0, 1);
p_test = mapminmax('apply', P_test, ps_input);
[t_train, ps_output] = mapminmax(T_train, 0, 1);
t_test = mapminmax('apply', T_test, ps_output);
2.GMM參數(shù)設(shè)置
% GMM參數(shù)設(shè)置
iter = 25; % 迭代次數(shù)
Cov_type = 'full'; %協(xié)方差矩陣的類型
N_inputs = min(size(p_train'));%輸入維度
N_outputs = min(size(t_train'));%輸出維度
N_mixtures = 3;%高斯混合模型混合數(shù)
3.GMM仿真預(yù)測及評價指標(biāo)計(jì)算
%% 仿真預(yù)測
t_sim1 = GMM( p_train', N_inputs, N_outputs, N_mixtures, Cov_type);
t_sim2 = GMM( p_test', N_inputs, N_outputs, N_mixtures, Cov_type);
%% 數(shù)據(jù)反歸一化
T_sim1 = mapminmax('reverse', t_sim1, ps_output)';
T_sim2 = mapminmax('reverse', t_sim2, ps_output)';
%% 均方根誤差
error1 = sqrt(sum((T_sim1 - T_train).^2) ./ M);
error2 = sqrt(sum((T_sim2 - T_test ).^2) ./ N);
%% 繪圖
figure()
subplot(2,1,1)
plot(1: M, T_train, 'r-*', 1: M, T_sim1, 'b-o', 'LineWidth', 1)
legend('真實(shí)值', '預(yù)測值')
xlabel('預(yù)測樣本')
ylabel('預(yù)測結(jié)果')
string = {'GMM訓(xùn)練集預(yù)測結(jié)果對比'; ['RMSE=' num2str(error1)]};
title(string)
xlim([1, M])
grid
subplot(2,1,2)
plot(1: N, T_test, 'r-*', 1: N, T_sim2, 'b-o', 'LineWidth', 1)
legend('真實(shí)值', '預(yù)測值')
xlabel('預(yù)測樣本')
ylabel('預(yù)測結(jié)果')
string = {'GMM測試集預(yù)測結(jié)果對比'; ['RMSE=' num2str(error2)]};
title(string)
xlim([1, N])
grid
%% 相關(guān)指標(biāo)計(jì)算
% R2
R1 = 1 - norm(T_train - T_sim1)^2 / norm(T_train - mean(T_train))^2;
R2 = 1 - norm(T_test - T_sim2)^2 / norm(T_test - mean(T_test ))^2;
disp(['訓(xùn)練集數(shù)據(jù)的R2為:', num2str(R1)])
disp(['測試集數(shù)據(jù)的R2為:', num2str(R2)])
% MAE
mae1 = sum(abs(T_sim1 - T_train)) ./ M ;
mae2 = sum(abs(T_sim2 - T_test )) ./ N ;
disp(['訓(xùn)練集數(shù)據(jù)的MAE為:', num2str(mae1)])
disp(['測試集數(shù)據(jù)的MAE為:', num2str(mae2)])
% MAPE mape = mean(abs((YReal - YPred)./YReal));
mape1 = mean(abs((T_train - T_sim1)./T_train));
mape2 = mean(abs((T_test - T_sim2 )./T_test));
disp(['訓(xùn)練集數(shù)據(jù)的MAPE為:', num2str(mape1)])
disp(['測試集數(shù)據(jù)的MAPE為:', num2str(mape2)])
三、代碼獲取
后臺私信回復(fù)“61期”即可獲取下載鏈接。文章來源地址http://www.zghlxwxcb.cn/news/detail-616633.html
到了這里,關(guān)于【MATLAB第61期】基于MATLAB的GMM高斯混合模型回歸數(shù)據(jù)預(yù)測的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!