This commit is contained in:
Arkadiusz Kondas 2017-04-19 22:28:07 +02:00
parent e1854d44a2
commit 6296e44db0
4 changed files with 8 additions and 12 deletions

View File

@ -11,7 +11,6 @@ use Phpml\Helper\Optimizer\GD;
use Phpml\Classification\Classifier; use Phpml\Classification\Classifier;
use Phpml\Preprocessing\Normalizer; use Phpml\Preprocessing\Normalizer;
use Phpml\IncrementalEstimator; use Phpml\IncrementalEstimator;
use Phpml\Helper\PartiallyTrainable;
class Perceptron implements Classifier, IncrementalEstimator class Perceptron implements Classifier, IncrementalEstimator
{ {
@ -95,7 +94,7 @@ class Perceptron implements Classifier, IncrementalEstimator
* @param array $targets * @param array $targets
* @param array $labels * @param array $labels
*/ */
public function partialTrain(array $samples, array $targets, array $labels = array()) public function partialTrain(array $samples, array $targets, array $labels = [])
{ {
return $this->trainByLabel($samples, $targets, $labels); return $this->trainByLabel($samples, $targets, $labels);
} }
@ -107,7 +106,6 @@ class Perceptron implements Classifier, IncrementalEstimator
*/ */
public function trainBinary(array $samples, array $targets, array $labels) public function trainBinary(array $samples, array $targets, array $labels)
{ {
if ($this->normalizer) { if ($this->normalizer) {
$this->normalizer->transform($samples); $this->normalizer->transform($samples);
} }

View File

@ -44,7 +44,7 @@ trait OneVsRest
* @param array $allLabels All training set labels * @param array $allLabels All training set labels
* @return void * @return void
*/ */
protected function trainByLabel(array $samples, array $targets, array $allLabels = array()) protected function trainByLabel(array $samples, array $targets, array $allLabels = [])
{ {
// Overwrites the current value if it exist. $allLabels must be provided for each partialTrain run. // Overwrites the current value if it exist. $allLabels must be provided for each partialTrain run.
@ -129,14 +129,13 @@ trait OneVsRest
*/ */
private function binarizeTargets($targets, $label) private function binarizeTargets($targets, $label)
{ {
$notLabel = "not_$label"; $notLabel = "not_$label";
foreach ($targets as $key => $target) { foreach ($targets as $key => $target) {
$targets[$key] = $target == $label ? $label : $notLabel; $targets[$key] = $target == $label ? $label : $notLabel;
} }
$labels = array($label, $notLabel); $labels = [$label, $notLabel];
return array($targets, $labels); return [$targets, $labels];
} }

View File

@ -12,5 +12,5 @@ interface IncrementalEstimator
* @param array $targets * @param array $targets
* @param array $labels * @param array $labels
*/ */
public function partialTrain(array $samples, array $targets, array $labels = array()); public function partialTrain(array $samples, array $targets, array $labels = []);
} }

View File

@ -6,12 +6,11 @@ namespace Phpml\SupportVectorMachine;
use Phpml\Helper\Trainable; use Phpml\Helper\Trainable;
class SupportVectorMachine class SupportVectorMachine
{ {
use Trainable; use Trainable;
/** /**
* @var int * @var int
*/ */
private $type; private $type;