*/ public function compatibility() : array { return [ EstimatorType::classifier(), EstimatorType::anomalyDetector(), ]; } /** * Score a set of predictions. * * @param list $predictions * @param list $labels * @return float */ public function score(array $predictions, array $labels) : float { PredictionAndLabelCountsAreEqual::with($predictions, $labels)->check(); if (empty($predictions)) { return 0.0; } $classes = array_unique(array_merge($predictions, $labels)); $truePos = $trueNeg = $falsePos = $falseNeg = array_fill_keys($classes, 0); foreach ($predictions as $i => $prediction) { $label = $labels[$i]; if ($prediction == $label) { ++$truePos[$prediction]; foreach ($classes as $class) { if ($class != $prediction) { ++$trueNeg[$class]; } } } else { ++$falsePos[$prediction]; ++$falseNeg[$label]; } } $scores = array_map([self::class, 'compute'], $truePos, $trueNeg, $falsePos, $falseNeg); return Stats::mean($scores); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'Informedness'; } }