当前位置:网站首页>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
边栏推荐
- Key points of data link layer and network layer protocol
- Anan's judgment
- Ml self realization /knn/ classification / weightlessness
- Neural network and deep learning-5-perceptron-pytorch
- 数据链路层及网络层协议要点
- Height of life
- leetcode 866. Prime Palindrome | 866. 回文素数
- JVM memory and garbage collection-3-object instantiation and memory layout
- Le chemin du poisson et des crevettes
- XXL job of distributed timed tasks
猜你喜欢
Matlab r2021b installing libsvm
牛熊周期与加密的未来如何演变?看看红杉资本怎么说
Clickhouse principle analysis and application practice "reading notes (8)
Applet running under the framework of fluent 3.0
[knowledge map] interpretable recommendation based on knowledge map through deep reinforcement learning
Deeppath: a reinforcement learning method of knowledge graph reasoning
LeetCode精选200道--数组篇
Summary of log feature selection (based on Tianchi competition)
Flutter 3.0框架下的小程序运行
leetcode 869. Reordered Power of 2 | 869. Reorder to a power of 2 (state compression)
随机推荐
2022年5月互联网医疗领域月度观察
[error] error loading H5 weight attributeerror: 'STR' object has no attribute 'decode‘
Flutter 3.0框架下的小程序运行
See how names are added to namespace STD from cmath file
Why did MySQL query not go to the index? This article will give you a comprehensive analysis
cv2-drawline
2022国内十大工业级三维视觉引导企业一览
C language -cmake cmakelists Txt tutorial
EMQX 5.0 发布:单集群支持 1 亿 MQTT 连接的开源物联网消息服务器
Alo who likes TestMan
[target tracking] |atom
数据链路层及网络层协议要点
node js 保持长连接
JVM memory and garbage collection-3-direct memory
BizDevOps与DevOps的关系
[knowledge map paper] Devine: a generative anti imitation learning framework for knowledge map reasoning
LeetCode精选200道--链表篇
力扣5_876. 链表的中间结点
Why did MySQL query not go to the index? This article will give you a comprehensive analysis
VR/AR 的产业发展与技术实现