p = $p; $this->backend = new Serial(); } /** * Test the estimator with the supplied dataset and return a validation score. * * @param Learner $estimator * @param Labeled $dataset * @param Metric $metric * @throws InvalidArgumentException * @return float */ public function test(Learner $estimator, Labeled $dataset, Metric $metric) : float { EstimatorIsCompatibleWithMetric::with($estimator, $metric)->check(); $n = (int) round($dataset->numSamples() / $this->p); $this->backend->flush(); for ($i = 0; $i < $n; ++$i) { $training = clone $dataset; $testing = $training->splice($i * $this->p, $this->p); $this->backend->enqueue( new TrainAndValidate($estimator, $training, $testing, $metric) ); } $scores = $this->backend->process(); return Stats::mean($scores); } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return "Leave P Out (p: {$this->p})"; } }