Skip to content

Commit

Permalink
Update to Rubix ML 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Jan 1, 2021
1 parent e2c2d7b commit d7b71f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md → LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 The Rubix ML Community
Copyright (c) 2020 Rubix ML
Copyright (c) 2020 Andrew DalPino

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ On the map ...
>- Dua, D. and Graff, C. (2019). UCI Machine Learning Repository [http://archive.ics.uci.edu/ml]. Irvine, CA: University of California, School of Information and Computer Science.
## License
The code is licensed [MIT](LICENSE.md) and the tutorial is licensed [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/).
The code is licensed [MIT](LICENSE) and the tutorial is licensed [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/).
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "project",
"description": "Use the K Nearest Neighbors algorithm to predict the probability of a divorce.",
"homepage": "https://github.com/RubixML/Divorce",
"license": "Apache-2.0",
"license": "MIT",
"keywords": [
"classification", "cross validation", "dataset", "data science", "divorce prediction",
"example project", "k nearest neighbors", "knn", "machine learning", "ml", "php",
Expand All @@ -12,14 +12,13 @@
"authors": [
{
"name": "Andrew DalPino",
"email": "me@andrewdalpino.com",
"homepage": "https://andrewdalpino.com",
"homepage": "https://github.com/andrewdalpino",
"role": "Lead Engineer"
}
],
"require": {
"php": ">=7.2",
"rubix/ml": "^0.1.0-rc2"
"rubix/ml": "^0.3.0"
},
"scripts": {
"train": "@php train.php"
Expand Down
17 changes: 8 additions & 9 deletions train.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,32 @@

include __DIR__ . '/vendor/autoload.php';

use Rubix\ML\Other\Loggers\Screen;
use Rubix\ML\Datasets\Labeled;
use Rubix\ML\Extractors\NDJSON;
use Rubix\ML\Classifiers\KNearestNeighbors;
use Rubix\ML\CrossValidation\Metrics\Accuracy;

echo 'Loading data into memory ...' . PHP_EOL;
$logger = new Screen();

$logger->info('Loading data into memory');

$dataset = Labeled::fromIterator(new NDJSON('dataset.ndjson'));

[$training, $testing] = $dataset->stratifiedSplit(0.8);

$estimator = new KNearestNeighbors(3);

echo 'Training ...' . PHP_EOL;
$logger->info('Training');

$estimator->train($training);

echo 'Making predictions ...' . PHP_EOL;

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

echo 'Example predictions:' . PHP_EOL;
$logger->info('Making predictions');

print_r(array_slice($predictions, 0, 3));
$predictions = $estimator->predict($testing);

$metric = new Accuracy();

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

echo 'Accuracy is ' . (string) ($score * 100.0) . '%' . PHP_EOL;
$logger->info("Accuracy is $score");

0 comments on commit d7b71f2

Please sign in to comment.