*/ public function compatibility() : array { return [ EstimatorType::regressor(), ]; } /** * 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; } $mean = Stats::mean($labels); $ssr = $sst = 0.0; foreach ($predictions as $i => $prediction) { $label = $labels[$i]; $ssr += ($label - $prediction) ** 2; $sst += ($label - $mean) ** 2; } return 1.0 - ($ssr / ($sst ?: EPSILON)); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'R Squared'; } }