📊 Linear Regression Calculator
📐 计算公式
最小二乘线性拟合 y = a·x + b:斜率 a = (nΣxy − Σx·Σy) ÷ [nΣx² − (Σx)²],截距 b = (Σy − a·Σx) ÷ n;R² = (nΣxy − Σx·Σy)² ÷ {斜率分母×[nΣy² − (Σy)²]}(分母为 0 时记 1),r = √|R²|×斜率符号,RMSE = √(SSE ÷ n)。校验:至少 2 组「x,y」数据点,所有 x 相同提示无法拟合直线。判据:R² ≥0.9 线性相关性强、≥0.6 中等相关、其余相关性较弱。
基于最小二乘线性回归,对 n 组 (x,y) 求斜率 a,配合截距 b 得到拟合直线 y=a·x+b,用于趋势预测与相关性分析。
Accepts x,y data pairs, one per line with comma or space separators, and fits a least-squares regression line y=ax+b together with the coefficient of determination R squared.
💡 最小二乘法:斜率 a = (n·Σxy − Σx·Σy) ÷ (n·Σx² − (Σx)²);截距 b = (Σy − a·Σx) ÷ n;相关系数 R² = [ (n·Σxy − Σx·Σy) ]² ÷ [ (n·Σx² − (Σx)²) · (n·Σy² − (Σy)²) ]。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Least squares | Minimise residual sum of squares | Legendre 1805 |
| Regression coefficients | b = Sxy/Sxx | Regression analysis |
| Intercept | a = ȳ − b·x̄ | Regression basics |
| R squared | R² = 1 − SSE/SST | Coefficient of determination |
| Correlation | r = Sxy/√(Sxx·Syy) | Pearson 1895 |
| Residual diagnostics | Residuals i.i.d., no trend | Regression diagnostics |
⚠️ 使用说明与注意事项
- 至少需要 2 组有效数据点才能拟合
- 每行格式:x,y(逗号、空格或制表符分隔)
- R² 越接近1表示线性相关性越强
- 本工具纯前端运行,数据不会上传到服务器
🕘 最近计算
暂无计算记录