HEX
Server: Apache
System: Linux webm010.cluster103.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: iestorre (46869)
PHP: 8.0.30
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/i/e/s/iestorre/moodleAW/moodle310/lib/mlbackend/php/phpml/src/Phpml/Metric/Accuracy.php
<?php

declare(strict_types=1);

namespace Phpml\Metric;

use Phpml\Exception\InvalidArgumentException;

class Accuracy
{
    /**
     * @param array $actualLabels
     * @param array $predictedLabels
     * @param bool  $normalize
     *
     * @return float|int
     *
     * @throws InvalidArgumentException
     */
    public static function score(array $actualLabels, array $predictedLabels, bool $normalize = true)
    {
        if (count($actualLabels) != count($predictedLabels)) {
            throw InvalidArgumentException::arraySizeNotMatch();
        }

        $score = 0;
        foreach ($actualLabels as $index => $label) {
            if ($label == $predictedLabels[$index]) {
                ++$score;
            }
        }

        if ($normalize) {
            $score /= count($actualLabels);
        }

        return $score;
    }
}