diff --git a/src/Phpml/Dataset/ArrayDataset.php b/src/Phpml/Dataset/ArrayDataset.php index b2e09b7..580df0a 100644 --- a/src/Phpml/Dataset/ArrayDataset.php +++ b/src/Phpml/Dataset/ArrayDataset.php @@ -11,12 +11,12 @@ class ArrayDataset implements Dataset /** * @var array */ - private $samples = []; + protected $samples = []; /** * @var array */ - private $labels = []; + protected $labels = []; /** * @param array $samples diff --git a/src/Phpml/Dataset/CsvDataset.php b/src/Phpml/Dataset/CsvDataset.php index c21ac97..de540c9 100644 --- a/src/Phpml/Dataset/CsvDataset.php +++ b/src/Phpml/Dataset/CsvDataset.php @@ -6,7 +6,7 @@ namespace Phpml\Dataset; use Phpml\Exception\DatasetException; -abstract class CsvDataset implements Dataset +class CsvDataset extends ArrayDataset { /** * @var string @@ -14,19 +14,12 @@ abstract class CsvDataset implements Dataset protected $filepath; /** - * @var array + * @param string|null $filepath + * + * @throws DatasetException */ - private $samples = []; - - /** - * @var array - */ - private $labels = []; - - public function __construct() + public function __construct(string $filepath = null) { - $filepath = dirname(__FILE__).'/../../../data/'.$this->filepath; - if (!file_exists($filepath)) { throw DatasetException::missingFile(basename($filepath)); } @@ -46,20 +39,4 @@ abstract class CsvDataset implements Dataset throw DatasetException::cantOpenFile(basename($filepath)); } } - - /** - * @return array - */ - public function getSamples(): array - { - return $this->samples; - } - - /** - * @return array - */ - public function getLabels(): array - { - return $this->labels; - } } diff --git a/src/Phpml/Dataset/Demo/Iris.php b/src/Phpml/Dataset/Demo/Iris.php index d544a55..5a4789e 100644 --- a/src/Phpml/Dataset/Demo/Iris.php +++ b/src/Phpml/Dataset/Demo/Iris.php @@ -15,7 +15,11 @@ use Phpml\Dataset\CsvDataset; class Iris extends CsvDataset { /** - * @var string + * @param string|null $filepath */ - protected $filepath = 'iris.csv'; + public function __construct(string $filepath = null) + { + $filepath = dirname(__FILE__).'/../../../../data/iris.csv'; + parent::__construct($filepath); + } }