diff --git a/src/Phpml/Dataset/Dataset.php b/src/Phpml/Dataset/Dataset.php index 316ee1d..cf1574e 100644 --- a/src/Phpml/Dataset/Dataset.php +++ b/src/Phpml/Dataset/Dataset.php @@ -1,9 +1,67 @@ filepath; + + if(!file_exists($filepath)) { + throw DatasetException::missingFile(basename($filepath)); + } + + $row = 0; + if (($handle = fopen($filepath, "r")) !== FALSE) { + while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { + $row++; + if($row==1) { + continue; + } + $this->samples[] = array_slice($data, 0, 4); + $this->lables[] = $data[4]; + } + fclose($handle); + } else { + throw DatasetException::cantOpenFile(basename($filepath)); + } + + } + + /** + * @return array + */ + public function getSamples() + { + return $this->samples; + } + + /** + * @return array + */ + public function getLabels() + { + return $this->lables; + } + } diff --git a/src/Phpml/Dataset/Iris.php b/src/Phpml/Dataset/Iris.php index 0565558..b862a74 100644 --- a/src/Phpml/Dataset/Iris.php +++ b/src/Phpml/Dataset/Iris.php @@ -1,9 +1,20 @@ assertEquals(150, count($iris->getSamples())); + $this->assertEquals(150, count($iris->getLabels())); + + // one sample features count + $this->assertEquals(4, count($iris->getSamples()[0])); + } + +} \ No newline at end of file