PHP-ML机器学习脚本预测获胜团队

时间:2019-02-13 19:46:35

标签: php python machine-learning

我正在使用此脚本https://php-ml.readthedocs.io/en/latest/来预测特定游戏的结果。

训练数据集如下:

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

H,A,D为结果(主场,客场,抽签)

我尝试使用他们的示例,但是如果我使用字符串而不是整数(并且可能也不是正确的公式)会出现错误:

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

当我尝试使用字符串时,这是我得到的错误:

  

警告:第29行上的C:\ xampp12 \ htdocs \ ml-football \ vendor \ php-ai \ php-ml \ src \ Phpml \ Math \ Distance \ Euclidean.php中遇到的非数字值   PHP警告:在第29行的C:\ xampp12 \ htdocs \ ml-football \ vendor \ php-ai \ php-ml \ src \ Phpml \ Math \ Distance \ Euclidean.php中遇到非数值

任何人都可以给我看我想要的结果的例子吗?

1 个答案:

答案 0 :(得分:0)

您在这里使用K-nearest neighbours algorithm。这是一种分类算法。这些数字是点坐标的X,Y。因此您不能使用字符串。最好使用神经网络算法,但是如果要使用分类。您也可以在这里找到Description of how to use k-neighbours for sport prediction。使用此数据集,您将无法正确预测。借助此数据集,您可以计算出一支球队获胜的次数,因此最有实力的球队甚至有可能获胜。