Score a set of predictions.

@param array $predictions
@param array $labels
@throws \InvalidArgumentException
@return float
487429
public function score(array $predictions, array $labels) : float
    {
        if (empty($predictions)) {
            return 0.;
        }

        if (count($predictions) !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $table = (new ContingencyTable())->generate($predictions, $labels);

        $score = 0.;

        foreach ($table as $dist) {
            $score += max($dist) / (array_sum($dist) ?: EPSILON);
        }

        return $score / count($table);
    }
1146527
public function generate(array $predictions, array $labels) : array
    {
        if (count($predictions) !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $classes = array_unique($labels);
        $clusters = array_unique($predictions);

        $table = array_fill_keys($clusters, array_fill_keys($classes, 0));

        foreach ($labels as $i => $class) {
            $table[$predictions[$i]][$class]++;
        }

        return $table;
    }
754269
public function score(Learner $estimator, Labeled $dataset) : float
    {
        return $this->validator->test($estimator, $dataset, $this->metric);
    }
699347
public static function mean(array $values, ?int $n = null) : float
    {
        $n = $n ?? count($values);

        if ($n < 1) {
            throw new InvalidArgumentException('Mean is undefined for empty'
                . ' set.');
        }

        return array_sum($values) / $n;
    }
249199
public function predict(Dataset $dataset) : array
    {
        if (empty($this->samples) or empty($this->labels)) {
            throw new RuntimeException('The learner has not'
                . ' been trained.');
        }

        DatasetIsCompatibleWithEstimator::check($dataset, $this);

        $predictions = [];

        foreach ($dataset as $sample) {
            [$labels, $distances] = $this->nearest($sample);

            if ($this->weighted) {
                $weights = array_fill_keys($labels, 0.);

                foreach ($labels as $i => $label) {
                    $weights[$label] += 1. / (1. + $distances[$i]);
                }
            } else {
                $weights = array_count_values($labels);
            }

            $predictions[] = argmax($weights);
        }

        return $predictions;
    }
907128
public function generate(array $predictions, array $labels) : array
    {
        if (count($predictions) !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $muHat = Stats::mean($labels);

        $errors = $l1 = $l2 = [];

        $sse = $sst = 0.;

        foreach ($predictions as $i => $prediction) {
            $label = $labels[$i];

            $errors[] = $error = $label - $prediction;

            $l1[] = abs($error);
            $l2[] = $t = $error ** 2;

            $sse += $t;
            $sst += ($label - $muHat) ** 2;
        }

        [$mean, $variance] = Stats::meanVar($errors);

        $mse = Stats::mean($l2);

        $r2 = 1. - ($sse / ($sst ?: EPSILON));

        return [
            'mean_absolute_error' => Stats::mean($l1),
            'median_absolute_error' => Stats::median($l1),
            'mean_squared_error' => $mse,
            'rms_error' => sqrt($mse),
            'mean_squared_log_error' => log($mse),
            'r_squared' => $r2,
            'error_mean' => $mean,
            'error_variance' => $variance,
            'error_skewness' => Stats::skewness($errors, $mean),
            'error_kurtosis' => Stats::kurtosis($errors, $mean),
            'error_min' => min($errors),
            'error_max' => max($errors),
            'cardinality' => count($predictions),
        ];
    }
992864
def draw_predictions(img, boxes, scores):
    
    if len(boxes) == 0:
        return img
    labels = scores.argmax(axis=1)
    scores = scores.max(axis=1)
    tags = ["{},{:.2f}".format(cfg.DATA.CLASS_NAMES[lb], score) for lb, score in zip(labels, scores)]
    return viz.draw_boxes(img, boxes, tags)
1154897
public function labels($labels = null)
    {
        if ($labels === null)
        {
            return $this->_labels;
        }

        $this->_labels = $labels;
        return $this;
    }
488327
protected function getValidationLabelsForElements(array $labels = [])
    {
        $this->getElements()->onlyActive()->each(function ($element) use (&$labels) {
            $element = $this->getElementContainer($element);

            if ($element instanceof Validable) {
                $labels += $element->getValidationLabels();
            }
        });

        return $labels;
    }
1011658
public function score(array $predictions, array $labels) : float
    {
        if (empty($predictions)) {
            return 0.;
        }

        $n = count($predictions);

        if ($n !== count($labels)) {
            throw new InvalidArgumentException('The number of labels'
                . ' must equal the number of predictions.');
        }

        $table = Matrix::build((new ContingencyTable())->generate($predictions, $labels));

        $sigma = $table->map([self::class, 'comb'])->sum()->sum();

        $alpha = $table->sum()->map([self::class, 'comb'])->sum();
        $beta = $table->transpose()->sum()->map([self::class, 'comb'])->sum();

        $pHat = ($alpha * $beta) / self::comb($n);
        $mean = ($alpha + $beta) / 2.;

        return ($sigma - $pHat) / ($mean - $pHat);
    }
1109995
public static function fromIterator(iterable $samples, iterable $labels) : self
    {
        $samples = is_array($samples)
            ? $samples
            : iterator_to_array($samples, false);

        $labels = is_array($labels)
            ? $labels
            : iterator_to_array($labels, false);

        return self::build($samples, $labels);
    }
1028777
protected function labelsToRaw(array $labels)
    {
        $final = [];

        foreach ($labels as $label) {
            if ($label->isPlain) {
                return $label->text;
            }

            $final[$label->lang] = $label->text;
        }

        return (object) $final;
    }
3005
public void setLabels(INDArray... labels) {
        if (labels != null && labels.length != this.numOutputArrays) {
            throw new IllegalArgumentException("Invalid output array: network has " + numOutputArrays
                    + " outputs, but array is of length " + labels.length);
        }
        this.labels = labels;
    }
1360176
protected function predictProbability(array $sample, $label): float
    {
        $predicted = $this->predictSampleBinary($sample);

        if ((string) $predicted == (string) $label) {
            $sample = $this->checkNormalizedSample($sample);

            return (float) abs($this->output($sample));
        }

        return 0.0;
    }
1086993
public double score(List<L> guesses, List<L> trueLabels) {
    clearCounts();
    addGuesses(guesses, trueLabels);
    finalizeCounts();
    return getFMeasure();
  }
383780
public function columns($columnName, $label = null)
    {
        if (!is_string($columnName)) {
            throw new \InvalidArgumentException('$columnName must be set');
        }

        if ($this->resetColumns) {
            $this->columns = [];
            $this->resetColumns = false;
        }
        if (is_null($label)) {
            $label = $columnName;
        }
        $this->columns[$columnName] = $label;
        return $this;
    }
1355878
protected function score(Dataset $dataset) : array
    {
        $scores = array_fill(
            0,
            $dataset->numRows(),
            array_fill_keys($this->classes, 0.)
        );

        foreach ($this->ensemble as $i => $estimator) {
            $influence = $this->influences[$i];

            foreach ($estimator->predict($dataset) as $j => $prediction) {
                $scores[$j][$prediction] += $influence;
            }
        }

        return $scores;
    }