当前位置:网站首页>MATLAB小技巧(21)矩阵分析--偏最小二乘回归
MATLAB小技巧(21)矩阵分析--偏最小二乘回归
2022-06-29 08:39:00 【mozun2020】
MATLAB小技巧(21)矩阵分析--偏最小二乘回归
前言
MATLAB进行图像处理相关的学习是非常友好的,可以从零开始,对基础的图像处理都已经有了封装好的许多可直接调用的函数,这个系列文章的话主要就是介绍一些大家在MATLAB中常用一些概念函数进行例程演示!
偏最小二乘法是一种数学优化技术,它通过最小化误差的平方和找到一组数据的最佳函数匹配。 用最简的方法求得一些绝对不可知的真值,而令误差平方之和为最小。 很多其他的优化问题也可通过最小化能量或最大化熵用最小二乘形式表达。
与传统多元线性回归模型相比,偏最小二乘法的特点是:
1、能够在自变量存在严重多重相关性的条件下进行回归建模。
2、允许在样本点个数少于变量个数的条件下进行回归建模。
3、偏最小二乘回归在最终模型中将包含原有的所有自变量。
4、偏最小二乘回归模型更易于辨识系统信息与噪声。
5、在偏最小二乘回归模型中,每一个自变量的回归系数将更容易解释。
在计算方差和协方差时,求和号前面的系数有两种取法:当样本点集合是随机抽取得到时,应该取1/(n-1);如果不是随机抽取的,这个系数可取1/n。搜寻资料的时候看到的这个示例,这里分享给大家,MATLAB版本为MATLAB2015b。
一. MATLAB仿真
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%功能:矩阵分析--偏最小二乘回归
%环境:Win7,Matlab2015b
%Modi: C.S
%时间:2022-06-26
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% I. 清空环境变量
clear all
clc
tic
%% II. 导入数据
load spectra;
%% III. 随机划分训练集与测试集
temp = randperm(size(NIR, 1));
% temp = 1:60;
%%
% 1. 训练集——50个样本
P_train = NIR(temp(1:50),:);
T_train = octane(temp(1:50),:);
%%
% 2. 测试集——10个样本
P_test = NIR(temp(51:end),:);
T_test = octane(temp(51:end),:);
%% IV. PLS回归模型
%%
% 1. 创建模型
k = 2;
[Xloadings,Yloadings,Xscores,Yscores,betaPLS,PLSPctVar,MSE,stats] = plsregress(P_train,T_train,k);
%%
% 2. 主成分贡献率分析
figure
percent_explained = 100 * PLSPctVar(2,:) / sum(PLSPctVar(2,:));
pareto(percent_explained)
xlabel('主成分')
ylabel('贡献率(%)')
title('主成分贡献率')
%%
% 3. 预测拟合
N = size(P_test,1);
T_sim = [ones(N,1) P_test] * betaPLS;
%% V. 结果分析与绘图
%%
% 1. 相对误差error
error = abs(T_sim - T_test) ./ T_test;
%%
% 2. 决定系数R^2
R2 = (N * sum(T_sim .* T_test) - sum(T_sim) * sum(T_test))^2 / ((N * sum((T_sim).^2) - (sum(T_sim))^2) * (N * sum((T_test).^2) - (sum(T_test))^2));
%%
% 3. 结果对比
result = [T_test T_sim error]
%%
% 4. 绘图
figure
plot(1:N,T_test,'b:*',1:N,T_sim,'r-o')
legend('真实值','预测值','location','best')
xlabel('预测样本')
ylabel('辛烷值')
string = {
'测试集辛烷值含量预测结果对比';['R^2=' num2str(R2)]};
title(string)
toc
二. 仿真结果
result =
88.9000 88.6958 0.0023
88.7500 88.3616 0.0044
87.0500 87.0516 0.0000
88.3500 88.4744 0.0014
88.8500 89.1747 0.0037
88.5500 88.6033 0.0006
87.3000 87.4689 0.0019
88.7000 88.9760 0.0031
84.6000 84.6464 0.0005
89.6000 88.6938 0.0101
时间已过 1.684586 秒。


三. 小结
偏最小二乘回归进行预测分析的示例,最小二乘是比较常用的在各类算法中的都比较常见的基础算法,对算法感兴趣的同学,建议还是从原理,公式推导好好理解学习,本示例后期可能会用到,所以这里做个笔记。每天学一个MATLAB小知识,大家一起来学习进步阿!
边栏推荐
- 如何将谷歌浏览器设置为默认浏览器
- Which securities company is good for opening a mobile account? Is it safe to open an account online?
- pytorch总结学习系列-操作
- 通识篇:原型设计的认知,设计及最佳实践
- Wechat applet project: wechat applet page layout
- train_ on_ Batch save the image of the loss function change
- Wechat applet sharing page, sharing to the circle of friends
- 实例报错IOPub data rate exceeded
- Pytorch learning summary - memory cost of operation
- jar包和war包
猜你喜欢

How to do unit test well

基于区域注意的通用目标检测

# 《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(四)

Gd32f4xx Ethernet Chip (ENC28J60) Drive transplantation

easyexecl导出100万行execl报字体错误的解决办法

Laravel 8 enables the order table to be divided by month level

Detailed version of two-stage target detection principle

Simplicity Studio无法识别新买的JLink v9解决方法

YOLO Nano:一种高度紧凑的只看一次的卷积神经网络用于目标检测

Summary of 3DMAX jamming, white screen and rendering crash
随机推荐
Self cultivation (XXI) servlet life cycle, service method source code analysis, thread safety issues
How to do unit test well
Pytorch Summary - sensor on GPU
微信小程序项目:微信小程序页面布局
HB5470民用飞机机舱内部非金属材料燃烧测试
pytorch总结学习系列-数据操作
Augfpn: improved multiscale feature learning for target detection
Wechat applet determines the file format of URL
超融合架构和传统架构有什么区别?
Universal target detection based on region attention
爱快安装或重置后,PC或手机端获取不到ip
train_ on_ Batch save the image of the loss function change
手机开户一般哪个证券公司好?究竟网上开户是否安全么?
Share code snippets of wechat applet
pytorch学习总结—运算的内存开销
Recursive RBAC menu level display infinite classification
ServerApp.iopub
Handwriting Redux thunk
Highlight in the middle of the navigation bar at the bottom of wechat applet
How to implement observer mode