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