mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-16 10:15:13 +00:00
svm is hard :(
This commit is contained in:
parent
37782eba98
commit
118ee0b5fe
@ -6,20 +6,21 @@ namespace Phpml\Classifier;
|
|||||||
|
|
||||||
use Phpml\Classifier\Traits\Predictable;
|
use Phpml\Classifier\Traits\Predictable;
|
||||||
use Phpml\Classifier\Traits\Trainable;
|
use Phpml\Classifier\Traits\Trainable;
|
||||||
|
use Phpml\Math\Kernel;
|
||||||
|
|
||||||
class SupportVectorMachine implements Classifier
|
class SupportVectorMachine implements Classifier
|
||||||
{
|
{
|
||||||
use Trainable, Predictable;
|
use Trainable, Predictable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var float
|
* @var Kernel
|
||||||
*/
|
*/
|
||||||
private $gamma;
|
private $kernel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var float
|
* @var float
|
||||||
*/
|
*/
|
||||||
private $epsilon;
|
private $C;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var float
|
* @var float
|
||||||
@ -32,20 +33,23 @@ class SupportVectorMachine implements Classifier
|
|||||||
private $upperBound;
|
private $upperBound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param float $gamma
|
* @param Kernel $kernel
|
||||||
* @param float $epsilon
|
* @param float $C
|
||||||
* @param float $tolerance
|
* @param float $tolerance
|
||||||
* @param int $upperBound
|
* @param int $upperBound
|
||||||
*/
|
*/
|
||||||
public function __construct(float $gamma = .5, float $epsilon = .001, float $tolerance = .001, int $upperBound = 100)
|
public function __construct(Kernel $kernel = null, float $C = 1.0, float $tolerance = .001, int $upperBound = 100)
|
||||||
{
|
{
|
||||||
$this->gamma = $gamma;
|
if (null === $kernel) {
|
||||||
$this->epsilon = $epsilon;
|
$kernel = new Kernel\RBF($gamma = .001);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->kernel = $kernel;
|
||||||
|
$this->C = $C;
|
||||||
$this->tolerance = $tolerance;
|
$this->tolerance = $tolerance;
|
||||||
$this->upperBound = $upperBound;
|
$this->upperBound = $upperBound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $sample
|
* @param array $sample
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user