Enter paired (x, y) sample data to fit the line y = ax + b by least squares, output the slope a, intercept b, correlation and goodness of fit, and predict y for any x.
📐 计算公式 / 原理
斜率 a = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²);截距 b = (Σy − aΣx) / n;预测 ŷ = a·x + b
用最小二乘法对 5 对 (x, y) 样本拟合直线 y = ax + b:斜率 a 由 x、y 的协方差与 x 的方差之比求得,截距 b 保证回归线过样本均值点 (x̄, ȳ)。代入任意 x 即可预测 ŷ,用于趋势分析与数据建模。
📐 计算公式与说明
a = (nΣxy − ΣxΣy) / (nΣx² − (Σx)²) b = (Σy − aΣx) / n