| 1 | <?php |
||
| 9 | class LeastSquares implements Regression |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | private $samples; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | private $targets; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var float |
||
| 23 | */ |
||
| 24 | private $intercept; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | private $coefficients; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param array $samples |
||
| 33 | * @param array $targets |
||
| 34 | */ |
||
| 35 | public function train(array $samples, array $targets) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param array $sample |
||
| 45 | * |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | public function predict($sample) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | public function getCoefficients() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * coefficient(b) = (X'X)-1X'Y. |
||
| 68 | */ |
||
| 69 | private function computeCoefficients() |
||
| 80 | } |
||
| 81 |