0

I am using this script https://php-ml.readthedocs.io/en/latest/ to predict the result of a particular game.

The training dataset looks like this:

team1, team2, H
team3, team4, A
team6, team12, D
team1, team4, ?

H, A, D being the results (Home, Away, Drawn)

I tried using their example, but I get an error if I use strings instead of integers (and maybe that one is no the right formula also):

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]);

When I try with strings this is the error that I get:

Warning: A non-numeric value encountered in C:\xampp12\htdocs\ml-football\vendor\php-ai\php-ml\src\Phpml\Math\Distance\Euclidean.php on line 29 PHP Warning: A non-numeric value encountered in C:\xampp12\htdocs\ml-football\vendor\php-ai\php-ml\src\Phpml\Math\Distance\Euclidean.php on line 29

Anyone can show me an example of the results that I am looking for?

neubert
  • 15,947
  • 24
  • 120
  • 212

1 Answers1

0

You are using K-nearest neighbours algorithm here. It's a classification algorithm. Those numbers are X, Y of a point's coordination. so you cannot use strings instead. It's better to use Neural Network algorithms, but if you want to use classification. Here also you can find Description of how to use k-neighbours for sport prediction. With this dataset you cannot predict correctly. With this dataset you can count how many times a team has won so is the most powerful team and probably wins.