1. Go to this page and download the library: Download rubix/churn 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/ */
use Rubix\ML\Extractors\CSV;
$training->exportTo(new CSV('training.csv'), overwrite: true);
$testing->exportTo(new CSV('testing.csv'), overwrite: true);
use Rubix\ML\BayesianSearch;
use Rubix\ML\Classifiers\LogitBoost;
use Rubix\ML\Regressors\RegressionTree;
$estimator = BayesianSearch::fromNamedParams(
class: LogitBoost::class,
params: [
'booster' => [
new RegressionTree(3, 1),
new RegressionTree(4, 1),
new RegressionTree(3, 5),
new RegressionTree(4, 5),
new RegressionTree(3, 10),
new RegressionTree(4, 10),
],
'rate' => [0.1, 0.3, 0.5],
'ratio' => [0.3, 0.5, 0.7],
],
initialTrials: 3,
maxTrials: 10
);
use Rubix\ML\Loggers\Screen;
$logger = new Screen();
$estimator->setLogger($logger);
$estimator->setup(function (LogitBoost $estimator) use ($testing) {
$estimator->setValidationDataset($testing);
});
$estimator->train($training);
var_dump($estimator->base()->params());
echo $estimator->results();
use Rubix\ML\Persisters\Filesystem;
$estimator->results()->toJSON()->saveTo(new Filesystem('results.json'));
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
$estimator = new PersistentModel($estimator->base(), new Filesystem('model.rbx'));
$estimator->save();
use Rubix\ML\Extractors\CSV;
use Rubix\ML\Datasets\Labeled;
$extractor = new CSV('testing.csv');
$dataset = Labeled::fromIterator($extractor);
use Rubix\ML\PersistentModel;
use Rubix\ML\Persisters\Filesystem;
$estimator = PersistentModel::load(new Filesystem('model.rbx'));
use Rubix\ML\Transformers\FloatTypeConverter;
$dataset->apply(new FloatTypeConverter());
$predictions = $estimator->predict($dataset);
use Rubix\ML\CrossValidation\Reports\AggregateReport;
use Rubix\ML\CrossValidation\Reports\ConfusionMatrix;
use Rubix\ML\CrossValidation\Reports\MulticlassBreakdown;
$reportGenerator = new AggregateReport([
new MulticlassBreakdown(),
new ConfusionMatrix(),
]);