mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-23 23:28:24 +00:00
linear regression is also hard
This commit is contained in:
parent
46da769ca6
commit
af3b57692f
@ -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)
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Math;
|
||||
|
||||
interface Kernel
|
||||
{
|
||||
|
||||
/**
|
||||
* @param float $a
|
||||
* @param float $b
|
||||
@ -13,5 +13,4 @@ interface Kernel
|
||||
* @return float
|
||||
*/
|
||||
public function compute($a, $b);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Math\Kernel;
|
||||
|
||||
@ -35,5 +36,4 @@ class RBF implements Kernel
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Math;
|
||||
|
||||
class Product
|
||||
{
|
||||
|
||||
/**
|
||||
* @param array $a
|
||||
* @param array $b
|
||||
@ -21,5 +21,4 @@ class Product
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
}
|
||||
|
37
src/Phpml/Regression/LeastSquares.php
Normal file
37
src/Phpml/Regression/LeastSquares.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Regression;
|
||||
|
||||
class LeastSquares implements Regression
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $features;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $targets;
|
||||
|
||||
/**
|
||||
* @param array $features
|
||||
* @param array $targets
|
||||
*/
|
||||
public function train(array $features, array $targets)
|
||||
{
|
||||
$this->features = $features;
|
||||
$this->targets = $targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $features
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function predict(array $features)
|
||||
{
|
||||
}
|
||||
}
|
21
src/Phpml/Regression/Regression.php
Normal file
21
src/Phpml/Regression/Regression.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace Phpml\Regression;
|
||||
|
||||
interface Regression
|
||||
{
|
||||
/**
|
||||
* @param array $features
|
||||
* @param array $targets
|
||||
*/
|
||||
public function train(array $features, array $targets);
|
||||
|
||||
/**
|
||||
* @param array $features
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function predict(array $features);
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace test\Phpml\Math\Kernel;
|
||||
|
||||
@ -7,7 +8,6 @@ use Phpml\Math\Kernel\RBF;
|
||||
|
||||
class RBFTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testComputeRBFKernelFunction()
|
||||
{
|
||||
$rbf = new RBF($gamma = 0.001);
|
||||
@ -22,5 +22,4 @@ class RBFTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(0.00451, $rbf->compute([1, 2, 3], [4, 5, 6]), '', $delta = 0.0001);
|
||||
$this->assertEquals(0, $rbf->compute([4, 5], [1, 100]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types = 1);
|
||||
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace tests\Phpml\Math;
|
||||
|
||||
@ -7,12 +8,10 @@ use Phpml\Math\Product;
|
||||
|
||||
class ProductTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testScalarProduct()
|
||||
{
|
||||
$this->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]));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user