denissimon/prediction-builder

一个使用线性回归构建预测的机器学习库。

v1.1.1 2020-01-25 15:38 UTC

This package is not auto-updated.

Last update: 2024-09-15 14:03:32 UTC


README

Latest Stable Version Total Downloads License

PredictionBuilder 是一个使用线性回归构建预测的机器学习库。

要求

此项目需要 PHP 5.4 或更高版本,因为使用了 trait 和短数组语法。

安装

您可以通过 Composer 安装此库。将其添加到项目的 composer.json 文件中

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

然后运行 php composer.phar install(或 composer install)。

示例

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";
}

返回的对象具有以下属性

$result->ln_model 适合数据的线性模型:"29.56362+10.46364x"

$result->cor 相关系数:0.8348

$result->x 给定的 x 值:4.5

$result->y 预测的 y 值:76.65

许可证

MIT 许可证 下授权