Read and write
.arff
files for Weka.
Developed by Florian Eckerstorfer in Vienna, Europe.
You can install cocur/arff
with Composer:
$ composer require cocur/arff
use Cocur\Arff\Document;
use Cocur\Arff\Column\NumericColumn;
use Cocur\Arff\Column\NominalColumn;
$document = new Document('iris');
$document->addColumn(new NumericColumn('sepallength'));
$document->addColumn(new NumericColumn('sepalwidth'));
$document->addColumn(new NumericColumn('petallength'));
$document->addColumn(new NumericColumn('petalwidth'));
$document->addColumn(new NominalColumn('class', ['Iris-setosa','Iris-versicolor','Iris-virginica']));
$document->addData(['sepallength' => 5.1, 'sepalwidth' => 3.5, 'petallength' => 1.4, 'petalwidth' => 0.2, 'class' => 'Iris-setosa']);
$writer = new Writer();
$writer->render($document); // returns rendered .arff file
$writer->write($document, 'iris.arff'); // writes .arff file to disk
use Cocur\Arff\Reader;
$reader = new Reader();
$document = $reader->readFile('irif.arff'); // returns Cocur\Arff\Document
Cocur\Arff\Column\NumericColumn
Cocur\Arff\Column\StringColumn
Cocur\Arff\Column\NominalColumn
Cocur\Arff\Column\DateColumn
You can define the date format for date columns. The format is only used to write to the Arff file, you need to convert the date manually before adding the data.
$column = new DateColumn('created', 'yyyy-MM-dd HH:mm:ss');
cocur/arff contains a writer for Plum.
use Cocur\Arff\Bridge\Plum\ArffWriter;
$writer = new ArffWriter('filename.arff', 'name', [
new NumericColumn('sepallength'),
new NumericColumn('sepalwidth'),
new NumericColumn('petallength'),
new NumericColumn('petalwidth'),
new NominalColumn('class', ['Iris-setosa','Iris-versicolor','Iris-virginica']),
]);
- #3 Support more generic relation name and drops malformed lines (by frantzmiccoli)
- Case-insensitive parsing of column type
- Fix parsing of nominal columns
- Split
ArffFile
intoCocur\Arff\Document
andCocur\Arff\Writer
- Add
Cocur\Arff\Reader
to read.arff
files
- Initial release
The MIT license applies to cocur/arff. For the full copyright and license information, please view the LICENSE file distributed with this source code.