mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-05 04:57:52 +00:00
Add delimiter option for CsvDataset (#66)
Useful option when the CSV file uses another delimiter character other than the comma, for example, as the semicolon or tab character.
This commit is contained in:
parent
49234429f0
commit
b27f08f420
@ -20,7 +20,7 @@ class CsvDataset extends ArrayDataset
|
||||
*
|
||||
* @throws FileException
|
||||
*/
|
||||
public function __construct(string $filepath, int $features, bool $headingRow = true)
|
||||
public function __construct(string $filepath, int $features, bool $headingRow = true, string $delimiter = ',')
|
||||
{
|
||||
if (!file_exists($filepath)) {
|
||||
throw FileException::missingFile(basename($filepath));
|
||||
@ -31,13 +31,13 @@ class CsvDataset extends ArrayDataset
|
||||
}
|
||||
|
||||
if ($headingRow) {
|
||||
$data = fgetcsv($handle, 1000, ',');
|
||||
$data = fgetcsv($handle, 1000, $delimiter);
|
||||
$this->columnNames = array_slice($data, 0, $features);
|
||||
} else {
|
||||
$this->columnNames = range(0, $features - 1);
|
||||
}
|
||||
|
||||
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
|
||||
while (($data = fgetcsv($handle, 1000, $delimiter)) !== false) {
|
||||
$this->samples[] = array_slice($data, 0, $features);
|
||||
$this->targets[] = $data[$features];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user