当前位置:网站首页>Matlab tips (21) matrix analysis -- partial least squares regression
Matlab tips (21) matrix analysis -- partial least squares regression
2022-06-29 09:32:00 【mozun2020】
MATLAB Tips (21) matrix analysis -- Partial least squares regression
Preface
MATLAB Learning about image processing is very friendly , You can start from scratch , There are many encapsulated functions that can be called directly for basic image processing , This series of articles is mainly to introduce some of you in MATLAB Some concept functions are commonly used in routine demonstration !
Partial least squares is a mathematical optimization technique , It finds the best function matching of a set of data by minimizing the sum of squares of errors . Use the simplest method to find some absolutely unknown truth values , And minimize the sum of the squares of the errors . Many other optimization problems can also be expressed in the form of least squares by minimizing energy or maximizing entropy .
Compared with the traditional multiple linear regression model , The characteristics of partial least squares are :
1、 Be able to carry out regression modeling under the condition of serious multiple correlation of independent variables .
2、 Regression modeling is allowed when the number of sample points is less than the number of variables .
3、 Partial least squares regression will include all original independent variables in the final model .
4、 Partial least squares regression model is easier to identify system information and noise .
5、 In the partial least squares regression model , The regression coefficient of each independent variable will be easier to explain .
When calculating variance and covariance , There are two ways to find the coefficient before the sum sign : When the set of sample points is randomly selected , We should take 1/(n-1); If it's not random , This coefficient can be taken as 1/n. This example I saw when searching for data , Here to share ,MATLAB Version is MATLAB2015b.
One . MATLAB Simulation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function : matrix analysis -- Partial least squares regression
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-26
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% I. Clear environment variables
clear all
clc
tic
%% II. Import data
load spectra;
%% III. Randomly divide the training set and the test set
temp = randperm(size(NIR, 1));
% temp = 1:60;
%%
% 1. Training set ——50 Samples
P_train = NIR(temp(1:50),:);
T_train = octane(temp(1:50),:);
%%
% 2. Test set ——10 Samples
P_test = NIR(temp(51:end),:);
T_test = octane(temp(51:end),:);
%% IV. PLS The regression model
%%
% 1. Creating models
k = 2;
[Xloadings,Yloadings,Xscores,Yscores,betaPLS,PLSPctVar,MSE,stats] = plsregress(P_train,T_train,k);
%%
% 2. Principal component contribution rate analysis
figure
percent_explained = 100 * PLSPctVar(2,:) / sum(PLSPctVar(2,:));
pareto(percent_explained)
xlabel(' The principal components ')
ylabel(' Contribution rate (%)')
title(' Principal component contribution rate ')
%%
% 3. Prediction fitting
N = size(P_test,1);
T_sim = [ones(N,1) P_test] * betaPLS;
%% V. Result analysis and mapping
%%
% 1. Relative error error
error = abs(T_sim - T_test) ./ T_test;
%%
% 2. Coefficient of determination 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. Results contrast
result = [T_test T_sim error]
%%
% 4. mapping
figure
plot(1:N,T_test,'b:*',1:N,T_sim,'r-o')
legend(' True value ',' Predictive value ','location','best')
xlabel(' Prediction samples ')
ylabel(' Octane number ')
string = {
' Comparison of prediction results of octane number content in test set ';['R^2=' num2str(R2)]};
title(string)
toc
Two . Simulation results
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
Time has passed 1.684586 second .


3、 ... and . Summary
Examples of partial least squares regression for predictive analysis , Least squares is a common basic algorithm in all kinds of algorithms , Students interested in algorithms , It is suggested to follow the principle , Formula derivation, understand and learn well , This example may be used later , So here's a note . Learn one every day MATLAB Little knowledge , Let's learn and make progress together !
边栏推荐
- Detecting and counting tiny faces
- 商业智能BI的未来,如何看待AI+BI这种模式?
- Written test question "arrange version numbers from large to small"
- 【目标检测】|指标 A probabilistic challenge for object detection
- 数据治理:数据标准管理(第三篇)
- train_ on_ Batch save the image of the loss function change
- Hb5470 combustion test of non-metallic materials in civil aircraft cabin
- Keras to tf Vgg19 input in keras_ shape
- LSM6DSL之SPI驱动
- 深卷积神经网络时代的目标检测研究进展
猜你喜欢

train_on_batch保存一下loss函数变化的图像

Have you done the network security "physical examination" this year?

Lffd: a lightweight fast face detector for edge detection

Western Polytechnic University, one of the "seven national defense schools", was attacked by overseas networks

数据可视化:数据可视化四象限,教你正确应用图标

Remember to customize the top navigation bar of wechat applet

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

用户级线程和内核级线程

Wechat applet user refuses to authorize geographic location information and calls up the authorization window again

Augfpn: improved multiscale feature learning for target detection
随机推荐
GD32F4xx 以太網芯片(enc28j60)驅動移植
pytorch总结学习系列-数据操作
3DMax 卡死、白屏、渲染死机问题总结
Print service IP setting scheme
[target detection] | indicator a probabilistic challenge for object detection
How to do unit test well
Reading notes on how to connect the network - Web server request and response (IV)
train_ on_ Batch save the image of the loss function change
What is the difference between hyperconverged architecture and traditional architecture?
Five heart charity matchmaker team
Twinmotion beginner tutorial
数据可视化:数据可视化的意义
pytorch总结学习系列-广播机制
The difference between cokkie and session
Mac mysql数据库基本操作
UE4 plug-in reports an error cannot open include file: 'modulemanager H 'resolve
Redo after JS rotation view (longer full version, can be run)
Network security issues
修改exif信息
Written test question "arrange version numbers from large to small"