From dfb7b6b108deb457bda393b007769202d09b6a54 Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Fri, 6 May 2016 22:38:50 +0200 Subject: [PATCH] datatransformer test set --- .../SupportVectorMachine/DataTransformer.php | 15 +++++++++++++++ .../SupportVectorMachine/SupportVectorMachine.php | 1 + .../SupportVectorMachine/DataTransformerTest.php | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/Phpml/SupportVectorMachine/DataTransformer.php b/src/Phpml/SupportVectorMachine/DataTransformer.php index 5b418e2..05599f1 100644 --- a/src/Phpml/SupportVectorMachine/DataTransformer.php +++ b/src/Phpml/SupportVectorMachine/DataTransformer.php @@ -23,6 +23,21 @@ class DataTransformer return $set; } + /** + * @param array $samples + * + * @return string + */ + public static function testSet(array $samples): string + { + $set = ''; + foreach ($samples as $sample) { + $set .= sprintf('0 %s %s', self::sampleRow($sample), PHP_EOL); + } + + return $set; + } + /** * @param array $labels * diff --git a/src/Phpml/SupportVectorMachine/SupportVectorMachine.php b/src/Phpml/SupportVectorMachine/SupportVectorMachine.php index 6842777..325fcf3 100644 --- a/src/Phpml/SupportVectorMachine/SupportVectorMachine.php +++ b/src/Phpml/SupportVectorMachine/SupportVectorMachine.php @@ -83,5 +83,6 @@ class SupportVectorMachine public function predict(array $samples) { + $testSet = DataTransformer::testSet(); } } diff --git a/tests/Phpml/SupportVectorMachine/DataTransformerTest.php b/tests/Phpml/SupportVectorMachine/DataTransformerTest.php index 1429511..ff2a7c7 100644 --- a/tests/Phpml/SupportVectorMachine/DataTransformerTest.php +++ b/tests/Phpml/SupportVectorMachine/DataTransformerTest.php @@ -22,4 +22,19 @@ class DataTransformerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($trainingSet, DataTransformer::trainingSet($samples, $labels)); } + + public function testTransformSamplesToTestSet() + { + $samples = [[1, 1], [2, 1], [3, 2], [4, 5]]; + + $testSet = + '0 1:1 2:1 '.PHP_EOL. + '0 1:2 2:1 '.PHP_EOL. + '0 1:3 2:2 '.PHP_EOL. + '0 1:4 2:5 '.PHP_EOL + ; + + $this->assertEquals($testSet, DataTransformer::testSet($samples)); + } + }