rename labels to targets for Dataset

This commit is contained in:
Arkadiusz Kondas 2016-06-16 23:56:15 +02:00
parent 7f4a0b243f
commit 4554011899
9 changed files with 16 additions and 16 deletions

View File

@ -44,7 +44,7 @@ class RandomSplit
$this->seedGenerator($seed);
$samples = $dataset->getSamples();
$labels = $dataset->getLabels();
$labels = $dataset->getTargets();
$datasetSize = count($samples);
for ($i = $datasetSize; $i > 0; --$i) {

View File

@ -16,22 +16,22 @@ class ArrayDataset implements Dataset
/**
* @var array
*/
protected $labels = [];
protected $targets = [];
/**
* @param array $samples
* @param array $labels
* @param array $targets
*
* @throws InvalidArgumentException
*/
public function __construct(array $samples, array $labels)
public function __construct(array $samples, array $targets)
{
if (count($samples) != count($labels)) {
if (count($samples) != count($targets)) {
throw InvalidArgumentException::arraySizeNotMatch();
}
$this->samples = $samples;
$this->labels = $labels;
$this->targets = $targets;
}
/**
@ -45,8 +45,8 @@ class ArrayDataset implements Dataset
/**
* @return array
*/
public function getLabels(): array
public function getTargets(): array
{
return $this->labels;
return $this->targets;
}
}

View File

@ -36,7 +36,7 @@ class CsvDataset extends ArrayDataset
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
$this->samples[] = array_slice($data, 0, $features);
$this->labels[] = $data[$features];
$this->targets[] = $data[$features];
}
fclose($handle);
}

View File

@ -14,5 +14,5 @@ interface Dataset
/**
* @return array
*/
public function getLabels(): array;
public function getTargets(): array;
}

View File

@ -24,6 +24,6 @@ class ArrayDatasetTest extends \PHPUnit_Framework_TestCase
);
$this->assertEquals($samples, $dataset->getSamples());
$this->assertEquals($labels, $dataset->getLabels());
$this->assertEquals($labels, $dataset->getTargets());
}
}

View File

@ -23,7 +23,7 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
$dataset = new CsvDataset($filePath, 2, true);
$this->assertEquals(10, count($dataset->getSamples()));
$this->assertEquals(10, count($dataset->getLabels()));
$this->assertEquals(10, count($dataset->getTargets()));
}
public function testSampleCsvDatasetWithoutHeaderRow()
@ -33,6 +33,6 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
$dataset = new CsvDataset($filePath, 2, false);
$this->assertEquals(11, count($dataset->getSamples()));
$this->assertEquals(11, count($dataset->getLabels()));
$this->assertEquals(11, count($dataset->getTargets()));
}
}

View File

@ -14,7 +14,7 @@ class GlassTest extends \PHPUnit_Framework_TestCase
// whole dataset
$this->assertEquals(214, count($glass->getSamples()));
$this->assertEquals(214, count($glass->getLabels()));
$this->assertEquals(214, count($glass->getTargets()));
// one sample features count
$this->assertEquals(9, count($glass->getSamples()[0]));

View File

@ -14,7 +14,7 @@ class IrisTest extends \PHPUnit_Framework_TestCase
// whole dataset
$this->assertEquals(150, count($iris->getSamples()));
$this->assertEquals(150, count($iris->getLabels()));
$this->assertEquals(150, count($iris->getTargets()));
// one sample features count
$this->assertEquals(4, count($iris->getSamples()[0]));

View File

@ -14,7 +14,7 @@ class WineTest extends \PHPUnit_Framework_TestCase
// whole dataset
$this->assertEquals(178, count($wine->getSamples()));
$this->assertEquals(178, count($wine->getLabels()));
$this->assertEquals(178, count($wine->getTargets()));
// one sample features count
$this->assertEquals(13, count($wine->getSamples()[0]));