mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-22 21:15:10 +00:00
rename labels to targets for Dataset
This commit is contained in:
parent
7f4a0b243f
commit
4554011899
@ -44,7 +44,7 @@ class RandomSplit
|
|||||||
$this->seedGenerator($seed);
|
$this->seedGenerator($seed);
|
||||||
|
|
||||||
$samples = $dataset->getSamples();
|
$samples = $dataset->getSamples();
|
||||||
$labels = $dataset->getLabels();
|
$labels = $dataset->getTargets();
|
||||||
$datasetSize = count($samples);
|
$datasetSize = count($samples);
|
||||||
|
|
||||||
for ($i = $datasetSize; $i > 0; --$i) {
|
for ($i = $datasetSize; $i > 0; --$i) {
|
||||||
|
@ -16,22 +16,22 @@ class ArrayDataset implements Dataset
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $labels = [];
|
protected $targets = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $samples
|
* @param array $samples
|
||||||
* @param array $labels
|
* @param array $targets
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @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();
|
throw InvalidArgumentException::arraySizeNotMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->samples = $samples;
|
$this->samples = $samples;
|
||||||
$this->labels = $labels;
|
$this->targets = $targets;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,8 +45,8 @@ class ArrayDataset implements Dataset
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getLabels(): array
|
public function getTargets(): array
|
||||||
{
|
{
|
||||||
return $this->labels;
|
return $this->targets;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class CsvDataset extends ArrayDataset
|
|||||||
|
|
||||||
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
|
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
|
||||||
$this->samples[] = array_slice($data, 0, $features);
|
$this->samples[] = array_slice($data, 0, $features);
|
||||||
$this->labels[] = $data[$features];
|
$this->targets[] = $data[$features];
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,5 @@ interface Dataset
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getLabels(): array;
|
public function getTargets(): array;
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,6 @@ class ArrayDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($samples, $dataset->getSamples());
|
$this->assertEquals($samples, $dataset->getSamples());
|
||||||
$this->assertEquals($labels, $dataset->getLabels());
|
$this->assertEquals($labels, $dataset->getTargets());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dataset = new CsvDataset($filePath, 2, true);
|
$dataset = new CsvDataset($filePath, 2, true);
|
||||||
|
|
||||||
$this->assertEquals(10, count($dataset->getSamples()));
|
$this->assertEquals(10, count($dataset->getSamples()));
|
||||||
$this->assertEquals(10, count($dataset->getLabels()));
|
$this->assertEquals(10, count($dataset->getTargets()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSampleCsvDatasetWithoutHeaderRow()
|
public function testSampleCsvDatasetWithoutHeaderRow()
|
||||||
@ -33,6 +33,6 @@ class CsvDatasetTest extends \PHPUnit_Framework_TestCase
|
|||||||
$dataset = new CsvDataset($filePath, 2, false);
|
$dataset = new CsvDataset($filePath, 2, false);
|
||||||
|
|
||||||
$this->assertEquals(11, count($dataset->getSamples()));
|
$this->assertEquals(11, count($dataset->getSamples()));
|
||||||
$this->assertEquals(11, count($dataset->getLabels()));
|
$this->assertEquals(11, count($dataset->getTargets()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class GlassTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// whole dataset
|
// whole dataset
|
||||||
$this->assertEquals(214, count($glass->getSamples()));
|
$this->assertEquals(214, count($glass->getSamples()));
|
||||||
$this->assertEquals(214, count($glass->getLabels()));
|
$this->assertEquals(214, count($glass->getTargets()));
|
||||||
|
|
||||||
// one sample features count
|
// one sample features count
|
||||||
$this->assertEquals(9, count($glass->getSamples()[0]));
|
$this->assertEquals(9, count($glass->getSamples()[0]));
|
||||||
|
@ -14,7 +14,7 @@ class IrisTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// whole dataset
|
// whole dataset
|
||||||
$this->assertEquals(150, count($iris->getSamples()));
|
$this->assertEquals(150, count($iris->getSamples()));
|
||||||
$this->assertEquals(150, count($iris->getLabels()));
|
$this->assertEquals(150, count($iris->getTargets()));
|
||||||
|
|
||||||
// one sample features count
|
// one sample features count
|
||||||
$this->assertEquals(4, count($iris->getSamples()[0]));
|
$this->assertEquals(4, count($iris->getSamples()[0]));
|
||||||
|
@ -14,7 +14,7 @@ class WineTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// whole dataset
|
// whole dataset
|
||||||
$this->assertEquals(178, count($wine->getSamples()));
|
$this->assertEquals(178, count($wine->getSamples()));
|
||||||
$this->assertEquals(178, count($wine->getLabels()));
|
$this->assertEquals(178, count($wine->getTargets()));
|
||||||
|
|
||||||
// one sample features count
|
// one sample features count
|
||||||
$this->assertEquals(13, count($wine->getSamples()[0]));
|
$this->assertEquals(13, count($wine->getSamples()[0]));
|
||||||
|
Loading…
Reference in New Issue
Block a user