i want to predict a unlabeled item from K-NEAREST neighbour alg. but in default K=1 from package machine learning readthedocs
how can I set K manually???
<?php
$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
$labels = ['yes', 'yes', 'no', 'yes', 'no', 'no'];
$class = new KNearestNeighbors();
$class->train($samples, $labels);
$class->predict(1,7);
?>
As you may further read in the documentation, you may define K
as following:
$class = new KNearestNeighbors($k=4);
Note that the default value of K
is 3.