*/ public function compatibility() : array { return [ EstimatorType::clusterer(), ]; } /** * Score a set of predictions. * * @param list $predictions * @param list $labels * @return float */ public function score(array $predictions, array $labels) : float { $table = (new ContingencyTable())->generate($labels, $predictions); $table = Matrix::build($table->toArray()); $sigma = $table->map([self::class, 'comb2'])->sum()->sum(); $alpha = $table->sum()->map([self::class, 'comb2'])->sum(); $beta = $table->transpose()->sum()->map([self::class, 'comb2'])->sum(); $pHat = ($alpha * $beta) / self::comb2(count($predictions)); $mean = ($alpha + $beta) / 2.0; return ($sigma - $pHat) / ($mean - $pHat); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'Rand Index'; } }