PHP-ML - Machine Learning library for PHP

Minimum PHP Version Latest Stable Version Build Status Documentation Status Total Downloads License Scrutinizer Code Quality

PHP-ML - Machine Learning library for PHP

Fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in one library.

PHP-ML requires PHP >= 7.0.

Simple example of classification:

require_once 'vendor/autoload.php';

use Phpml\Classification\KNearestNeighbors;

$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
$labels = ['a', 'a', 'a', 'b', 'b', 'b'];

$classifier = new KNearestNeighbors();
$classifier->train($samples, $labels);

$classifier->predict([3, 2]); 
// return 'b'


To find out how to use PHP-ML follow Documentation.


Currently this library is in the process of developing, but You can install it with Composer:

composer require php-ai/php-ml


Example scripts are available in a separate repository php-ai/php-ml-examples.



  • Issue Tracker:
  • Source Code:

You can find more about contributing in


PHP-ML is released under the MIT Licence. See the bundled LICENSE file for details.


Arkadiusz Kondas (@ArkadiuszKondas)