Skip to content

Commit

Permalink
Additional training for SVR (#59)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Kyle Warren authored and akondas committed Mar 17, 2017
1 parent 8be1956 commit c44f3b2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Phpml/SupportVectorMachine/SupportVectorMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

namespace Phpml\SupportVectorMachine;

use Phpml\Helper\Trainable;


class SupportVectorMachine
{
/**
use Trainable;

/**
* @var int
*/
private $type;
Expand Down Expand Up @@ -84,7 +89,7 @@ class SupportVectorMachine
/**
* @var array
*/
private $labels;
private $targets = [];

/**
* @param int $type
Expand Down Expand Up @@ -126,12 +131,14 @@ public function __construct(

/**
* @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;
$trainingSet = DataTransformer::trainingSet($samples, $labels, in_array($this->type, [Type::EPSILON_SVR, Type::NU_SVR]));
$this->samples = array_merge($this->samples, $samples);
$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);
$modelFileName = $trainingSetFileName.'-model';

Expand Down Expand Up @@ -176,7 +183,7 @@ public function predict(array $samples)
unlink($outputFileName);

if (in_array($this->type, [Type::C_SVC, Type::NU_SVC])) {
$predictions = DataTransformer::predictions($predictions, $this->labels);
$predictions = DataTransformer::predictions($predictions, $this->targets);
} else {
$predictions = explode(PHP_EOL, trim($predictions));
}
Expand Down

0 comments on commit c44f3b2

Please sign in to comment.