最小二乗法

「最小二乗法」の基本を、図とインタラクティブデモで学べる日本語版記事です。

RegressionLeast Squares

最小二乗法は「最も近い直線」をどう定めるか

単回帰では、データ点に一本の直線を当てはめます。
ここでいう「最も近い」とは、各点から回帰直線への縦方向距離(残差)の二乗和を最小にすることです。

1. 目的関数

最小二乗法では「残差の二乗和」を最小化します。
この量が小さいほど、直線がデータ全体によく適合していると解釈できます。

2. 係数の求め方

切片と傾きを変数として最小化問題を解くと、正規方程式が得られます。
そこから、傾きは x と y の共分散に比例し、x の分散で割った形になります。

3. 直感

可視化で赤い縦線(残差)を見ると、直線の傾きや切片を変えるたびに二乗和が変わります。
その二乗和が最小になる位置が、最小二乗解です。

まとめ

  • 最小二乗法は「誤差二乗和を最小にする」最適化問題。
  • 幾何的には、点群に最も近い直線を選ぶ方法と解釈できる。
  • 回帰分析における推定・予測の基礎となる。

Interactive Least Squares Regression

Regression Line: y = 1.10 + 0.95x
Sum of Squared Errors: 0.70
Drag the points to see how the regression line adjusts to minimize the sum of squared errors
XY
Data points (drag to move)
Regression line
Vertical distances (errors)
Mean point (x̄, ȳ)

Key Insights:

  • • The regression line always passes through the mean point (x̄, ȳ)
  • • Red dashed lines show the vertical distances from each point to the line
  • • The algorithm minimizes the sum of squared red distances
  • • Try moving points to see how the line responds instantly
← 図鑑に戻る