mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-09-26 22:19:03 +00:00
refactor csv dataset definition
This commit is contained in:
parent
d3247ebccb
commit
a20f474324
@ -11,12 +11,12 @@ class ArrayDataset implements Dataset
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $samples = [];
|
||||
protected $samples = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $labels = [];
|
||||
protected $labels = [];
|
||||
|
||||
/**
|
||||
* @param array $samples
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user