Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

niladrimahato96's avatar

Machine Learning in PHP

is there any plugin or library to do predictive analytics in laravel of user's recent searches, purchase's etc like amazon, flipkart or any other ecommerce website does. Here i don't want to host another server to run ML algorithms and do the prediction, I want to make a laravel website where i will send the data set to a library or plugin which will return the predictive data. Is there any plugin or library to do the prediction?

0 likes
1 reply
ChristophHarms's avatar

A quick google search brought me to PHP-ML, a lib which you just install with composer and then use it like this:

require_once __DIR__ . '/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'

So you could easily use that in a laravel project. But since it's the first result of a google search, you probably already found it and it doesn't suit your needs...

2 likes

Please or to participate in this conversation.