Phpml\Dataset\CsvDataset::__construct PHP Метод

__construct() публичный Метод

public __construct ( string $filepath, integer $features, boolean $headingRow = true )
$filepath string
$features integer
$headingRow boolean
    public function __construct(string $filepath, int $features, bool $headingRow = true)
    {
        if (!file_exists($filepath)) {
            throw DatasetException::missingFile(basename($filepath));
        }
        if (false === ($handle = fopen($filepath, 'r'))) {
            throw DatasetException::cantOpenFile(basename($filepath));
        }
        if ($headingRow) {
            fgets($handle);
        }
        while (($data = fgetcsv($handle, 1000, ',')) !== false) {
            $this->samples[] = array_slice($data, 0, $features);
            $this->targets[] = $data[$features];
        }
        fclose($handle);
    }

Usage Example

Пример #1
0
 public function __construct()
 {
     $filepath = dirname(__FILE__) . '/../../../../data/wine.csv';
     parent::__construct($filepath, 13, true);
 }
CsvDataset