From af3b57692fbda8292478842d4e860d0afa4e336b Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Mon, 25 Apr 2016 22:55:34 +0200 Subject: [PATCH] linear regression is also hard --- src/Phpml/Classifier/SupportVectorMachine.php | 6 +-- src/Phpml/Math/Kernel.php | 5 +-- src/Phpml/Math/Kernel/RBF.php | 4 +- src/Phpml/Math/Product.php | 5 +-- src/Phpml/Regression/LeastSquares.php | 37 +++++++++++++++++++ src/Phpml/Regression/Regression.php | 21 +++++++++++ tests/Phpml/Math/Kernel/RBFTest.php | 5 +-- tests/Phpml/Math/ProductTest.php | 7 ++-- 8 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 src/Phpml/Regression/LeastSquares.php create mode 100644 src/Phpml/Regression/Regression.php diff --git a/src/Phpml/Classifier/SupportVectorMachine.php b/src/Phpml/Classifier/SupportVectorMachine.php index e16ebbe..8ee3731 100644 --- a/src/Phpml/Classifier/SupportVectorMachine.php +++ b/src/Phpml/Classifier/SupportVectorMachine.php @@ -34,9 +34,9 @@ class SupportVectorMachine implements Classifier /** * @param Kernel $kernel - * @param float $C - * @param float $tolerance - * @param int $upperBound + * @param float $C + * @param float $tolerance + * @param int $upperBound */ public function __construct(Kernel $kernel = null, float $C = 1.0, float $tolerance = .001, int $upperBound = 100) { diff --git a/src/Phpml/Math/Kernel.php b/src/Phpml/Math/Kernel.php index 776f78c..953a5fa 100644 --- a/src/Phpml/Math/Kernel.php +++ b/src/Phpml/Math/Kernel.php @@ -1,11 +1,11 @@ features = $features; + $this->targets = $targets; + } + + /** + * @param array $features + * + * @return mixed + */ + public function predict(array $features) + { + } +} diff --git a/src/Phpml/Regression/Regression.php b/src/Phpml/Regression/Regression.php new file mode 100644 index 0000000..34e0b6d --- /dev/null +++ b/src/Phpml/Regression/Regression.php @@ -0,0 +1,21 @@ +assertEquals(0.00451, $rbf->compute([1, 2, 3], [4, 5, 6]), '', $delta = 0.0001); $this->assertEquals(0, $rbf->compute([4, 5], [1, 100])); } - } diff --git a/tests/Phpml/Math/ProductTest.php b/tests/Phpml/Math/ProductTest.php index ade9942..aba0ff2 100644 --- a/tests/Phpml/Math/ProductTest.php +++ b/tests/Phpml/Math/ProductTest.php @@ -1,5 +1,6 @@ assertEquals(10, Product::scalar([2, 3], [-1, 4])); $this->assertEquals(-0.1, Product::scalar([1, 4, 1], [-2, 0.5, -0.1])); $this->assertEquals(8, Product::scalar([2], [4])); } - -} \ No newline at end of file +}