当前位置:网站首页>Matlab tips (20) matrix analysis -- principal component regression
Matlab tips (20) matrix analysis -- principal component regression
2022-06-28 08:43:00 【mozun2020】
MATLAB Tips (20) matrix analysis -- Principal component 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 !
Principal component regression , Is a kind of regression analysis . When the independent variable has a complex collinear stiffness , Statistical analysis method for improving least square regression . Hotelling 1933 In, the principal component analysis was first used to analyze the related structures ,1965 Marcy proposed principal component regression in . Basic steps :(1) Convert argument to standard score ;(2) Find out the principal component of this standard score , Remove the small principal component of the characteristic root ;(3) The least square method is used to make the regression of the dependent variable to the retained principal component ;(4) Replace the principal components in the regression equation with the linear combination of standard components , Get the regression equation given by the standard score .
Principal component method is through linear transformation , Combine the original multiple indicators into a few independent indicators that can fully reflect the overall information , Thus, the problem of collinearity between variables can be avoided without losing important information , For further analysis . Each principal component extracted from the principal component analysis is a linear combination of the original multiple indicators . This is also an example encountered when searching for data , Here to share ,MATLAB Version is MATLAB2015b.
One . MATLAB Simulation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function : matrix analysis -- Principal component regression
% Environmental Science :Win7,Matlab2015b
%Modi: C.S
% Time :2022-06-25
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 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. Principal component analysis
%%
% 1. Principal component contribution rate analysis
[PCALoadings,PCAScores,PCAVar] = princomp(NIR);
figure
percent_explained = 100 * PCAVar / sum(PCAVar);
pareto(percent_explained)
xlabel(' The principal components ')
ylabel(' Contribution rate (%)')
title(' Principal component contribution rate ')
%%
% 2. First principal component vs. Second principal component
[PCALoadings,PCAScores,PCAVar] = princomp(P_train);
figure
plot(PCAScores(:,1),PCAScores(:,2),'r+')
hold on
[PCALoadings_test,PCAScores_test,PCAVar_test] = princomp(P_test);
plot(PCAScores_test(:,1),PCAScores_test(:,2),'o')
xlabel('1st Principal Component')
ylabel('2nd Principal Component')
legend('Training Set','Testing Set','location','best')
%% V. Principal component regression model
%%
% 1. Creating models
k = 4;
betaPCR = regress(T_train-mean(T_train),PCAScores(:,1:k));
betaPCR = PCALoadings(:,1:k) * betaPCR;
betaPCR = [mean(T_train)-mean(P_train) * betaPCR;betaPCR];
%%
% 2. Prediction fitting
N = size(P_test,1);
T_sim = [ones(N,1) P_test] * betaPCR;
%% VI. 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 =
87.0000 86.8053 0.0022
85.5000 85.3947 0.0012
88.6500 88.0991 0.0062
88.4000 87.9918 0.0046
84.7000 84.6877 0.0001
88.2500 87.7173 0.0060
88.0000 88.1574 0.0018
84.6000 84.4274 0.0020
88.8500 88.8830 0.0004
85.2500 84.8463 0.0047
Time has passed 1.935602 second .



3、 ... and . Summary
Examples of principal component regression , It is also the first to determine the data with high contribution value through principal component analysis , Then the model is obtained by training the training set , Compare with test set results , It turned out pretty well . Learn one every day MATLAB Little knowledge , Let's learn and make progress together !
边栏推荐
- Three body attack (three-dimensional split plus two points)
- Super Jumping! Jumping! Jumping!
- Potential safety hazards in elderly care facilities
- WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
- Cloudcompare & PCL point cloud clipping (based on closed surfaces or polygons)
- 【力扣10天SQL入门】Day5+6 合并表
- Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
- duilib 入门基础十二 样式类
- Which is a better ERP management system for electronic component sales?
- [learning notes] matroid
猜你喜欢

AWS saves data on the cloud (3)
![[cloud native | kubernetes] in depth understanding of pod (VI)](/img/ae/f16f5c090251ab603b88ddadff7eb3.png)
[cloud native | kubernetes] in depth understanding of pod (VI)

Kali Notes(1)
![Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...

【无标题】

隐私计算FATE-----离线预测

webrtc优势与模块拆分

Selenium+chromedriver cannot open Google browser page

Infinite penetration test

Discussion on safety management of centralized maintenance construction site of substation under the mode of operation and maintenance
随机推荐
[introduction to SQL in 10 days] day5+6 consolidated table
Sword finger offer 30 Stack containing min function
webrtc优势与模块拆分
Operating principle of Rogowski coil
How do people over 40 allocate annuity insurance? Which product is more suitable?
Error: `brew cask` is no longer a `brew` command. Use `brew <command> --cask` instead.
Comment supprimer le crosstalk SiC MOSFET?
Loss loss function
Basic twelve style classes for duilib
DB
Infinite penetration test
Characteristics and prevention of electrical fire
Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support
RAC enable archive log
Map. ToCharArray( ),Map. getOrDefault(). Map. charAt()
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...
Privacy computing fat----- offline prediction
Priority of JS operator
使用transform:scale之后导致页面鼠标悬浮事件消失
【无标题】