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
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $samples = [];
|
protected $samples = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $labels = [];
|
protected $labels = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $samples
|
* @param array $samples
|
||||||
|
@ -6,7 +6,7 @@ namespace Phpml\Dataset;
|
|||||||
|
|
||||||
use Phpml\Exception\DatasetException;
|
use Phpml\Exception\DatasetException;
|
||||||
|
|
||||||
abstract class CsvDataset implements Dataset
|
class CsvDataset extends ArrayDataset
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
@ -14,19 +14,12 @@ abstract class CsvDataset implements Dataset
|
|||||||
protected $filepath;
|
protected $filepath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @param string|null $filepath
|
||||||
|
*
|
||||||
|
* @throws DatasetException
|
||||||
*/
|
*/
|
||||||
private $samples = [];
|
public function __construct(string $filepath = null)
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
private $labels = [];
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
{
|
||||||
$filepath = dirname(__FILE__).'/../../../data/'.$this->filepath;
|
|
||||||
|
|
||||||
if (!file_exists($filepath)) {
|
if (!file_exists($filepath)) {
|
||||||
throw DatasetException::missingFile(basename($filepath));
|
throw DatasetException::missingFile(basename($filepath));
|
||||||
}
|
}
|
||||||
@ -46,20 +39,4 @@ abstract class CsvDataset implements Dataset
|
|||||||
throw DatasetException::cantOpenFile(basename($filepath));
|
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
|
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