From 5170c1077325f5c0b929f2934d9955de37bd716a Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Sat, 16 Apr 2016 21:34:50 +0200 Subject: [PATCH] simplify csv dataset --- src/Phpml/Dataset/CsvDataset.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Phpml/Dataset/CsvDataset.php b/src/Phpml/Dataset/CsvDataset.php index dca2792..f2c8ca7 100644 --- a/src/Phpml/Dataset/CsvDataset.php +++ b/src/Phpml/Dataset/CsvDataset.php @@ -29,16 +29,15 @@ class CsvDataset extends ArrayDataset if(false === $handle = fopen($filepath, 'r')) { throw DatasetException::cantOpenFile(basename($filepath)); } - $row = 0; + + if ($headingRow) { + fgets($handle); + } + 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); - } }