change csv dataset constructor

This commit is contained in:
Arkadiusz Kondas 2016-04-16 21:26:58 +02:00
parent a4ab370a48
commit dea6972305

View File

@ -26,19 +26,19 @@ class CsvDataset extends ArrayDataset
throw DatasetException::missingFile(basename($filepath));
}
$row = 0;
if (($handle = fopen($filepath, 'r')) !== false) {
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
++$row;
if ($headingRow && $row == 1) {
continue;
}
$this->samples[] = array_slice($data, 0, $features);
$this->labels[] = $data[$features];
}
fclose($handle);
} else {
if(false === $handle = fopen($filepath, 'r')) {
throw DatasetException::cantOpenFile(basename($filepath));
}
$row = 0;
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
++$row;
if ($headingRow && $row == 1) {
continue;
}
$this->samples[] = array_slice($data, 0, $features);
$this->labels[] = $data[$features];
}
fclose($handle);
}
}