mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-05 04:57:52 +00:00
change csv dataset constructor
This commit is contained in:
parent
a4ab370a48
commit
dea6972305
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user