当前位置:网站首页>Principle of least square method and matlab code implementation
Principle of least square method and matlab code implementation
2022-07-08 02:10:00 【Strawberry sauce toast】
Incomplete sorting , It's just a note for you to read .
One 、 Some of the problems
1. Least square method , The sum of the distance between the predicted value and the real value is the smallest , The principle is minimum mean square error .
2. Why square ?
- The square is positive or negative , It's a distance
- The square is equivalent to a weighting
Two 、 computational procedure
- Calculate the mean value of the input sequence
- Calculation x Variance and x,y The covariance ( Covariance reflects the variable x,y Whether the change trend of is the same )
- Calculate slope and intercept
3、 ... and 、Matlab Code implementation
function [a, b] = LeastSquaresFitting(X,Y)
% The least square method is used to fit the straight line
% Input : Fitting data X,Y
% Output :y=ax+b
if (length(X) ~= length(Y))
error('Length of input vectors must be equal.');
end
%% First step : O, respectively, x,y mean value
x_avg = sum(X(:))/length(X);
y_avg = sum(Y(:))/length(Y);
%% The second step : seek x,y Covariance and x The variance of
xy_cov = 0;
x_var = 0;
for i = 1:length(X)
xy_cov = xy_cov + (X(i)-x_avg)*(Y(i)-y_avg);
x_var = x_var + (X(i)-x_avg)^2;
end
%% The third step : Find the slope a Distance and intercept b
a = xy_cov/x_var;
b = y_avg - a*x_avg;
end
边栏推荐
猜你喜欢

给刚入门或者准备转行网络工程师的朋友一些建议

#797div3 A---C

JVM memory and garbage collection-3-runtime data area / method area

C language - modularization -clion (static library, dynamic library) use

Talk about the cloud deployment of local projects created by SAP IRPA studio

burpsuite

C language -cmake cmakelists Txt tutorial
![[knowledge map paper] Devine: a generative anti imitation learning framework for knowledge map reasoning](/img/c1/4c147a613ba46d81c6805cdfd13901.jpg)
[knowledge map paper] Devine: a generative anti imitation learning framework for knowledge map reasoning

Master go game through deep neural network and tree search

谈谈 SAP iRPA Studio 创建的本地项目的云端部署问题
随机推荐
2022年5月互联网医疗领域月度观察
[reinforcement learning medical] deep reinforcement learning for clinical decision support: a brief overview
leetcode 866. Prime Palindrome | 866. 回文素数
leetcode 869. Reordered Power of 2 | 869. Reorder to a power of 2 (state compression)
Semantic segmentation | learning record (1) semantic segmentation Preface
常见的磁盘格式以及它们之间的区别
C language - modularization -clion (static library, dynamic library) use
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
如何用Diffusion models做interpolation插值任务?——原理解析和代码实战
#797div3 A---C
云原生应用开发之 gRPC 入门
[target tracking] |dimp: learning discriminative model prediction for tracking
How to use diffusion models for interpolation—— Principle analysis and code practice
阿锅鱼的大度
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation
咋吃都不胖的朋友,Nature告诉你原因:是基因突变了
Nmap tool introduction and common commands
Introduction to grpc for cloud native application development
PHP 计算个人所得税
Introduction to Microsoft ad super Foundation