mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2025-01-10 00:37:55 +00:00
simplify csv dataset
This commit is contained in:
parent
dea6972305
commit
5170c10773
@ -29,16 +29,15 @@ class CsvDataset extends ArrayDataset
|
|||||||
if(false === $handle = fopen($filepath, 'r')) {
|
if(false === $handle = fopen($filepath, 'r')) {
|
||||||
throw DatasetException::cantOpenFile(basename($filepath));
|
throw DatasetException::cantOpenFile(basename($filepath));
|
||||||
}
|
}
|
||||||
$row = 0;
|
|
||||||
|
if ($headingRow) {
|
||||||
|
fgets($handle);
|
||||||
|
}
|
||||||
|
|
||||||
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
|
while (($data = fgetcsv($handle, 1000, ',')) !== false) {
|
||||||
++$row;
|
|
||||||
if ($headingRow && $row == 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$this->samples[] = array_slice($data, 0, $features);
|
$this->samples[] = array_slice($data, 0, $features);
|
||||||
$this->labels[] = $data[$features];
|
$this->labels[] = $data[$features];
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user