php-ml/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php

37 lines
786 B
PHP
Raw Normal View History

2016-05-05 21:29:11 +00:00
<?php
declare (strict_types = 1);
namespace tests\SupportVectorMachine;
use Phpml\SupportVectorMachine\Kernel;
use Phpml\SupportVectorMachine\SupportVectorMachine;
use Phpml\SupportVectorMachine\Type;
class SupportVectorMachineTest extends \PHPUnit_Framework_TestCase
{
public function testTrainCSVCModelWithLinearKernel()
{
$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
$labels = ['a', 'a', 'a', 'b', 'b', 'b'];
$model =
'svm_type c_svc
kernel_type linear
nr_class 2
total_sv 2
rho 0
label 0 1
nr_sv 1 1
SV
0.25 0:2 1:4
-0.25 0:4 1:2
';
$svm = new SupportVectorMachine(Type::C_SVC, Kernel::LINEAR, 100.0);
$svm->train($samples, $labels);
$this->assertEquals($model, $svm->getModel());
}
}