PHP code example of rubix / iris

1. Go to this page and download the library: Download rubix/iris library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rubix / iris example snippets


use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Transformers\FloatTypeConverter;

$training = Labeled::fromIterator(new CSV('dataset.csv', header: true))
    ->apply(new FloatTypeConverter());

$testing = $training->randomize()->take(10);

use Rubix\ML\Classifiers\KNearestNeighbors;

$estimator = new KNearestNeighbors(5);

$estimator->train($training);

$predictions = $estimator->predict($testing);

use Rubix\ML\CrossValidation\Metrics\Accuracy;

$metric = new Accuracy();

$score = $metric->score($predictions, $testing->labels());


use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Transformers\FloatTypeConverter;
use Rubix\ML\Classifiers\KNearestNeighbors;
use Rubix\ML\CrossValidation\Metrics\Accuracy;

$training = Labeled::fromIterator(new CSV('dataset.csv', header: true))
    ->apply(new FloatTypeConverter());

$testing = $training->randomize()->take(10);

$estimator = new KNearestNeighbors(5);

$estimator->train($training);

$predictions = $estimator->predict($testing);

$metric = new Accuracy();

$score = $metric->score($predictions, $testing->labels());


use Rubix\ML\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Transformers\FloatTypeConverter;
use Rubix\ML\Transformers\TSNE;

$logger = new Screen();

$dataset = Labeled::fromIterator(new CSV('dataset.csv', header: true))
    ->apply(new FloatTypeConverter());

$embedder = new TSNE(2, 100.0, perplexity: 10, exaggeration: 6.0, epochs: 1000);

$embedder->setLogger($logger);

$dataset->apply($embedder)->exportTo(new CSV('embeddings.csv'));
sh
php train.php
sh
php train.php
sh
php explore.php