| @@ 77-89 (lines=13) @@ | ||
| 74 | * @return float |
|
| 75 | * @throws IllegalArgumentException |
|
| 76 | */ |
|
| 77 | public static function mape(array $rightData, array $hypothesisData): float |
|
| 78 | { |
|
| 79 | $score = 0; |
|
| 80 | if (count($rightData) !== count($hypothesisData)) { |
|
| 81 | throw new IllegalArgumentException(self::ERROR_ARRAY_LENGTH); |
|
| 82 | } |
|
| 83 | ||
| 84 | foreach ($rightData as $k => $v) { |
|
| 85 | $score += abs($v - $hypothesisData[$k]) / $v; |
|
| 86 | } |
|
| 87 | ||
| 88 | return $score / count($rightData); |
|
| 89 | } |
|
| 90 | ||
| 91 | /** |
|
| 92 | * Mean absolute error |
|
| @@ 99-111 (lines=13) @@ | ||
| 96 | * @return float |
|
| 97 | * @throws IllegalArgumentException |
|
| 98 | */ |
|
| 99 | public static function mae(array $rightData, array $hypothesisData): float |
|
| 100 | { |
|
| 101 | $score = 0; |
|
| 102 | if (count($rightData) !== count($hypothesisData)) { |
|
| 103 | throw new IllegalArgumentException(self::ERROR_ARRAY_LENGTH); |
|
| 104 | } |
|
| 105 | ||
| 106 | foreach ($rightData as $k => $v) { |
|
| 107 | $score += abs($v - $hypothesisData[$k]); |
|
| 108 | } |
|
| 109 | ||
| 110 | return $score / count($rightData); |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * 1- mae |
|