Installation of PHP-ML Machine Learning Library (1)

1. PHP-ML library installation requirements: PHP>=7.1

2. Switch to the following directory of the project and use composer to install: composer require php-ai/php-ml

The directory after installation is as follows:

Create a new test file index.php, and the PHP-ML library is installed!

3. Initial use, open the index.php file

<?php
require_once __DIR__ .'/vendor/autoload.php';
# 引入最小二乘法线性回归类
use Phpml\Regression\LeastSquares;

# 定义样本数据集
$samples = [[12],[14],[17],[19],[22],[28]];
$target = [3.1,3.2,3.5,3.7,4.1,5];

# 实列化最小二乘法类
$regression = new LeastSquares();

# 训练样本
$regression->train($samples,$target);

# 预测
$res = $regression->predict([35]);
echo $res;

#结果:5.73

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324939242&siteId=291194637