mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-22 04:55:10 +00:00
add multi class svm test
This commit is contained in:
parent
95bfc890cd
commit
6cf6c5e768
@ -124,5 +124,4 @@ class SupportVectorMachine
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ SV
|
||||
$this->assertEquals($model, $svm->getModel());
|
||||
}
|
||||
|
||||
public function testPredictCSVCModelWithLinearKernel()
|
||||
public function testPredictSampleWithLinearKernel()
|
||||
{
|
||||
$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
|
||||
$labels = ['a', 'a', 'a', 'b', 'b', 'b'];
|
||||
@ -52,4 +52,31 @@ SV
|
||||
$this->assertEquals('a', $predictions[1]);
|
||||
$this->assertEquals('b', $predictions[2]);
|
||||
}
|
||||
|
||||
public function testPredictSampleFromMultipleClassWithRbfKernel()
|
||||
{
|
||||
$samples = [
|
||||
[1, 3], [1, 4], [1, 4],
|
||||
[3, 1], [4, 1], [4, 2],
|
||||
[-3, -1], [-4, -1], [-4, -2],
|
||||
];
|
||||
$labels = [
|
||||
'a', 'a', 'a',
|
||||
'b', 'b', 'b',
|
||||
'c', 'c', 'c',
|
||||
];
|
||||
|
||||
$svm = new SupportVectorMachine(Type::C_SVC, Kernel::RBF, 100.0);
|
||||
$svm->train($samples, $labels);
|
||||
|
||||
$predictions = $svm->predict([
|
||||
[1, 5],
|
||||
[4, 3],
|
||||
[-4, -3],
|
||||
]);
|
||||
|
||||
$this->assertEquals('a', $predictions[0]);
|
||||
$this->assertEquals('b', $predictions[1]);
|
||||
$this->assertEquals('c', $predictions[2]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user