首页
要闻详情
图标图标

线性回归

龙腾龙腾
关注
2023-03-07 16:10:34
632
线性回归是指利用最小二乘法计算出所选择的数据距离的一条直线。最小二乘法的和最小二乘法为比较哪一条直线与所选数据最接近提供了一个客观的衡量标准。1.绘出所给定的数据点。2.计算每点到给定的一条直...


线性回归是指利用最小二乘法计算出所选择的数据距离的一条直线。


最小二乘法的和
最小二乘法为比较哪一条直线与所选数据最接近提供了一个客观的衡量标准。
1. 绘出所给定的数据点。
2. 计算每点到给定的一条直线的距离。
3. 计算出该距离的平方数(为了便于去除负值)。
4. 计算出所有平方数的和。
5. 每一条可能的直线都重复步骤2、3、4
6. 根据第四步计算的平方和挑选出与所选数据最近的一条直线。


示例
下图表格展示了一条直线的最小二乘法计算步骤。
价格 = 20.50 + 0.11 * 天数n

 11.jpg
选定数据与每一条直线的距离的平方和都要分别计算出来。并选取平方和最小的一条直线。


数学计算公式
运用最小二乘法手动的计算每条可能直线的距离平方和将会消耗很多时间。幸运的是,下面是一种较为简便的方法:
目标直线的计算公式为: y = a + bx
• y 表示价格
• x 是日期
• a 是常数
• b 是直线的斜率
目标直线的计算公式为
b = ( nΣxy - ΣxΣy ) / ( nΣx² - (Σx)² )
a = ( Σy - bΣx ) / n


其中,n是所有选定数据的数值。


Linear Regression
Linear regression fits a straight line to the selected data using a method called the Sum Of Least Squares.
Sum Of Least Squares
The Sum Of Least Squares method provides an objective measure for comparing a number of straight lines to find the one that best fits the selected data.
1. Plot each data point in a table
2. Calculate the distance between each data point and the proposed straight line
3. Square the distances (to remove negative values)
4. Calculate the sum of the squares
5. Repeat steps 2 to 4 for each possible line
6. Select the line with the lowest sum of squares (from step 4).
EXAMPLE
The table below demonstrates how the sum of squares is calculated for a line where
Price = 20.50 + 0.11 * day n
The sum of squares is calculated for each possible line and the line with the lowest sum is selected.
Mathematical Formula
Manually calculating the sum of squares for each possible line would be enormously time-consuming. Fortunately there is a quicker way.
The formula for a straight line is
y = a + bx


For our purposes:
• y is the price
• x is the date
• a is the constant (the value when x equals zero)
• b is the slope of the line
The formula for calculating the line of best fit is
b = ( nΣxy - ΣxΣy ) / ( nΣx² - (Σx)² )
a = ( Σy - bΣx ) / n
Where n is the number of data points selected.


本文翻译由兄弟财经提供


文章来源:http://www.incrediblecharts.com/indicators/linear_regression.php

风险提示及免责声明

文章来源于兄弟财经,转载注明原文出处,此文观点与指股网无关,理性阅读,版权属于原作者若无意侵犯媒体或个人知识产权,请联系我们,本站将在第一时间删掉 ,指股网仅提供信息存储空间服务。

可信网站身份验证经营性网站备案信息工商网监电子标识网站安全证书
指股网浙ICP备17010029号-4
广播电视节目制作经营许可证:(浙)字第04719号
许可证图标网络文化经营许可证:浙网文(2018)9043-734号
备案图标浙公网安备:33010902002276号

本站郑重声明:指股网所有栏目频道仅提供信息存储空间服务。所载文章、数据仅供参考,风险自担!版权属于原作者若无意侵犯媒体或个人知识产权,请联系我们,本站将在第一时间处理。