add multi class svm test

This commit is contained in:
Arkadiusz Kondas 2016-05-07 14:08:09 +02:00
parent 95bfc890cd
commit 6cf6c5e768
2 changed files with 28 additions and 2 deletions

View File

@ -124,5 +124,4 @@ class SupportVectorMachine
return '';
}
}

View File

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