Inheritance: extends Phpml\SupportVectorMachine\SupportVectorMachine, implements Classifier
Example #1
0
 public function testPredictArrayOfSamplesWithLinearKernel()
 {
     $trainSamples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
     $trainLabels = ['a', 'a', 'a', 'b', 'b', 'b'];
     $testSamples = [[3, 2], [5, 1], [4, 3], [4, -5], [2, 3], [1, 2], [1, 5], [3, 10]];
     $testLabels = ['b', 'b', 'b', 'b', 'a', 'a', 'a', 'a'];
     $classifier = new SVC(Kernel::LINEAR, $cost = 1000);
     $classifier->train($trainSamples, $trainLabels);
     $predictions = $classifier->predict($testSamples);
     $this->assertEquals($testLabels, $predictions);
 }