mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-24 15:48:24 +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));
|
throw DatasetException::missingFile(basename($filepath));
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = 0;
|
if(false === $handle = fopen($filepath, 'r')) {
|
||||||
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 {
|
|
||||||
throw DatasetException::cantOpenFile(basename($filepath));
|
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…
x
Reference in New Issue
Block a user