Conditions | 6 |
Paths | 8 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
16 | public static function compute(array $actualLabels, array $predictedLabels, array $labels = null): array |
||
17 | { |
||
18 | $labels = $labels ? array_flip($labels) : self::getUniqueLabels($actualLabels); |
||
19 | $matrix = self::generateMatrixWithZeros($labels); |
||
20 | |||
21 | foreach ($actualLabels as $index => $actual) { |
||
22 | $predicted = $predictedLabels[$index]; |
||
23 | |||
24 | if (!isset($labels[$actual]) || !isset($labels[$predicted])) { |
||
25 | continue; |
||
26 | } |
||
27 | |||
28 | if ($predicted === $actual) { |
||
29 | $row = $column = $labels[$actual]; |
||
30 | } else { |
||
31 | $row = $labels[$actual]; |
||
32 | $column = $labels[$predicted]; |
||
33 | } |
||
34 | |||
35 | $matrix[$row][$column] += 1; |
||
36 | } |
||
37 | |||
38 | return $matrix; |
||
39 | } |
||
40 | |||
72 |