mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-24 15:48:24 +00:00
Additional training for SVR (#59)
* additional training SVR * additional training SVR, missed old labels reference * SVM labels parameter now targets * SVM member labels now targets * SVM init targets empty array
This commit is contained in:
parent
8be19567a2
commit
c44f3b2730
@ -4,9 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Phpml\SupportVectorMachine;
|
namespace Phpml\SupportVectorMachine;
|
||||||
|
|
||||||
|
use Phpml\Helper\Trainable;
|
||||||
|
|
||||||
|
|
||||||
class SupportVectorMachine
|
class SupportVectorMachine
|
||||||
{
|
{
|
||||||
/**
|
use Trainable;
|
||||||
|
|
||||||
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $type;
|
private $type;
|
||||||
@ -84,7 +89,7 @@ class SupportVectorMachine
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $labels;
|
private $targets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $type
|
* @param int $type
|
||||||
@ -126,12 +131,14 @@ class SupportVectorMachine
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $samples
|
* @param array $samples
|
||||||
* @param array $labels
|
* @param array $targets
|
||||||
*/
|
*/
|
||||||
public function train(array $samples, array $labels)
|
public function train(array $samples, array $targets)
|
||||||
{
|
{
|
||||||
$this->labels = $labels;
|
$this->samples = array_merge($this->samples, $samples);
|
||||||
$trainingSet = DataTransformer::trainingSet($samples, $labels, in_array($this->type, [Type::EPSILON_SVR, Type::NU_SVR]));
|
$this->targets = array_merge($this->targets, $targets);
|
||||||
|
|
||||||
|
$trainingSet = DataTransformer::trainingSet($this->samples, $this->targets, in_array($this->type, [Type::EPSILON_SVR, Type::NU_SVR]));
|
||||||
file_put_contents($trainingSetFileName = $this->varPath.uniqid('phpml', true), $trainingSet);
|
file_put_contents($trainingSetFileName = $this->varPath.uniqid('phpml', true), $trainingSet);
|
||||||
$modelFileName = $trainingSetFileName.'-model';
|
$modelFileName = $trainingSetFileName.'-model';
|
||||||
|
|
||||||
@ -176,7 +183,7 @@ class SupportVectorMachine
|
|||||||
unlink($outputFileName);
|
unlink($outputFileName);
|
||||||
|
|
||||||
if (in_array($this->type, [Type::C_SVC, Type::NU_SVC])) {
|
if (in_array($this->type, [Type::C_SVC, Type::NU_SVC])) {
|
||||||
$predictions = DataTransformer::predictions($predictions, $this->labels);
|
$predictions = DataTransformer::predictions($predictions, $this->targets);
|
||||||
} else {
|
} else {
|
||||||
$predictions = explode(PHP_EOL, trim($predictions));
|
$predictions = explode(PHP_EOL, trim($predictions));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user