Search code examples
phpmachine-learningphp-ml

How to populate sample in php machine learning library


$samples = [[0], [5], [10], [20], [25], [18], [30]];
$labels = ['fail', 'fail', 'pass', 'pass'];

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

echo $classifier->predict([14]);

The above code is from php machine library named php ml. The sample and label are hardcoded in the above code. What i want to do is fill the $sample array from database. But the problem i am seeing is i cannot figure it out as you can see its $sample = [[],[],[]] . Is it array with in an array? And how to populate it

I have populated the $label successfully from db.


Solution

  • That is how we can accomplish it. Thank you everyone

     while($row = mysqli_fetch_assoc($result)){
    
            array_push($samples, array($row['result_midterm']));
        }