PhpDev.App
denissimon/prediction-builder

denissimon/prediction-builder

Stars: 109

Forks: 13

Pull Requests: 0

Issues: 0

Watchers: 8

Last Updated: 2020-01-25 15:45:20

A library for machine learning that builds predictions using a linear regression.

License: MIT License

Languages: PHP

PredictionBuilder

Latest Stable Version Total Downloads License

PredictionBuilder is a library for machine learning that builds predictions using a linear regression.

Requirements

This project requires PHP 5.4 or higher because makes use of trait and short array syntax.

Installation

You can install the library by Composer. Add this to your project's composer.json:

"require": {
    "denissimon/prediction-builder": "*"
}

Then run php composer.phar install (or composer install).

Example

use PredictionBuilder\PredictionBuilder;

require_once __DIR__ . '/vendor/autoload.php';

$data = [[1,20],[2,70],[2,45],[3,81],[5,73],[6,80],[7,110]];
$x = 4.5;

// What is the expected y value for a given x value?
try {
    $prediction = new PredictionBuilder($x, $data);
    $result = $prediction->build(); // y = 76.65
} catch (\Exception $e) {
    echo $e->getMessage(), "\n";
}

The returned object has the following properties:

$result->ln_model linear model that fits the data: "29.56362+10.46364x"

$result->cor correlation coefficient: 0.8348

$result->x given x value: 4.5

$result->y predicted y value: 76.65

License

Licensed under the MIT License

OPEN ISSUES

See all