9.0, 10.0]; $y = [1.64, 2.05, 2.30, 2.90, 3.46, 4.09, 4.56, 5.00, 5.50, 6.10]; $a = (mt_rand(0, 100) - 50) * 0.01; $b = (mt_rand(0, 100) - 50) * 0.01; function f($x) { return $GLOBALS['a'] * $x + $GLOBALS['b']; } $ETA = 0.001; for ($loop = 0; $loop < 10000; $loop++) { $a_sum = $b_sum = 0; for ($i = 0; $i < count($x); $i++) { $a_sum += (f($x[$i]) - $y[$i]) * $x[$i]; $b_sum += (f($x[$i]) - $y[$i]); } $a = $a - $ETA * $a_sum; $b = $b - $ETA * $b_sum; } 以下の式の実装 a := a n i=0 f(x(i)) y(i) x(i) b := b n i=0 f(x(i)) y(i) PHPで回帰