From 4ac2ac8a353e45c91125cec58ff5c9cab0e0adbb Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Fri, 6 May 2016 22:33:04 +0200 Subject: [PATCH] fix index for trainging set --- src/Phpml/SupportVectorMachine/DataTransformer.php | 2 +- src/Phpml/SupportVectorMachine/SupportVectorMachine.php | 6 +++++- tests/Phpml/SupportVectorMachine/DataTransformerTest.php | 8 ++++---- .../SupportVectorMachine/SupportVectorMachineTest.php | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Phpml/SupportVectorMachine/DataTransformer.php b/src/Phpml/SupportVectorMachine/DataTransformer.php index 4e01fc8..5b418e2 100644 --- a/src/Phpml/SupportVectorMachine/DataTransformer.php +++ b/src/Phpml/SupportVectorMachine/DataTransformer.php @@ -51,7 +51,7 @@ class DataTransformer { $row = []; foreach ($sample as $index => $feature) { - $row[] = sprintf('%s:%s', $index, $feature); + $row[] = sprintf('%s:%s', $index + 1, $feature); } return implode(' ', $row); diff --git a/src/Phpml/SupportVectorMachine/SupportVectorMachine.php b/src/Phpml/SupportVectorMachine/SupportVectorMachine.php index 6e2be20..6842777 100644 --- a/src/Phpml/SupportVectorMachine/SupportVectorMachine.php +++ b/src/Phpml/SupportVectorMachine/SupportVectorMachine.php @@ -27,7 +27,7 @@ class SupportVectorMachine private $binPath; /** - * @var + * @var string */ private $varPath; @@ -80,4 +80,8 @@ class SupportVectorMachine { return $this->model; } + + public function predict(array $samples) + { + } } diff --git a/tests/Phpml/SupportVectorMachine/DataTransformerTest.php b/tests/Phpml/SupportVectorMachine/DataTransformerTest.php index 84fd001..1429511 100644 --- a/tests/Phpml/SupportVectorMachine/DataTransformerTest.php +++ b/tests/Phpml/SupportVectorMachine/DataTransformerTest.php @@ -14,10 +14,10 @@ class DataTransformerTest extends \PHPUnit_Framework_TestCase $labels = ['a', 'a', 'b', 'b']; $trainingSet = - '0 0:1 1:1 '.PHP_EOL. - '0 0:2 1:1 '.PHP_EOL. - '1 0:3 1:2 '.PHP_EOL. - '1 0:4 1:5 '.PHP_EOL + '0 1:1 2:1 '.PHP_EOL. + '0 1:2 2:1 '.PHP_EOL. + '1 1:3 2:2 '.PHP_EOL. + '1 1:4 2:5 '.PHP_EOL ; $this->assertEquals($trainingSet, DataTransformer::trainingSet($samples, $labels)); diff --git a/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php b/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php index e06f715..e4a8857 100644 --- a/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php +++ b/tests/Phpml/SupportVectorMachine/SupportVectorMachineTest.php @@ -24,8 +24,8 @@ rho 0 label 0 1 nr_sv 1 1 SV -0.25 0:2 1:4 --0.25 0:4 1:2 +0.25 1:2 2:4 +-0.25 1:4 2:2 '; $svm = new SupportVectorMachine(Type::C_SVC, Kernel::LINEAR, 100.0);