src/Formulas/Benchmark.php
public function calculate(): FormulasInterface
    {
        if (! $this->dataSet instanceof DataSet) {
            throw new WrongUsageException('DataSet was not provided for Accuracy calculus');
        }

        $correctGuesses = 0;
        $rmse = 0;

        foreach ($this->dataSet as $instance) {
            $result = $instance->getResult($this->algorithmName);

            if (! isset($result['result'])) {
                throw new WrongUsageException('Can not calculate accuracy before testing the dataSet');
            }

            if (abs($result['result'] - $instance->getOutput(0)) <= self::EPSILON ) {
                $correctGuesses ++;
            }

            $rmse += pow($result['result'] - $instance->getOutput(0), 2);
        }

        $accuracy = $correctGuesses / $this->dataSet->getSize();
        $rmse = sqrt($rmse / $this->dataSet->getSize());

        $this->result = [self::ACCURACY => $accuracy, self::RMSE => $rmse];

        return $this;
    }
public function calculate(): FormulasInterface
    {
        if (! $this->dataSet instanceof DataSet) {
            throw new WrongUsageException('DataSet was not provided for Accuracy calculus');
        }

        $correctGuesses = 0;
        $rmse = 0;

        foreach ($this->dataSet as $instance) {
            $result = $instance->getResult($this->algorithmName);

            if (! isset($result['result'])) {
                throw new WrongUsageException('Can not calculate accuracy before testing the dataSet');
            }

            if (abs($result['result'] - $instance->getOutput(0)) <= self::EPSILON ) {
                $correctGuesses ++;
            }

            $rmse += pow($result['result'] - $instance->getOutput(0), 2);
        }

        $accuracy = $correctGuesses / $this->dataSet->getSize();
        $rmse = sqrt($rmse / $this->dataSet->getSize());

        $this->result = [self::ACCURACY => $accuracy, self::RMSE => $rmse];

        return $this;
    }
calculates the accuracy and the RMSE for a dataSet after the fit and test are done :


NumberOfCorrectGuesses
accuracy =   -------------------------
NumberOfOutputs

and
Σ (prediction - output)^2
Rmse =        -------------------------
NumberOfOutputs


@return FormulasInterface
@throws WrongUsageException