A high-level machine learning and deep learning library with 40+ learning algorithms including ETL and cross-validation for the PHP language.
The project documentation is located in the /docs folder in the project root.
- PHP 8.3 or above.
- Tensor extension for fast Matrix/Vector computing.
- Swoole extension for multiprocessing support.
- GD extension for image support.
- Mbstring extension for fast multibyte string manipulation.
- SVM extension for Support Vector Machine engine (libsvm).
- PDO extension for relational database support.
- GraphViz for graph visualization.
| Command | Action |
|---|---|
composer test |
Run full PHPUnit testing suite |
composer analyze |
PHPStan static analysis |
composer check |
PHP-CS-Fixer dry-run (style check) |
composer fix |
PHP code style auto-fixer |
composer benchmark |
Run full PHPBench benchmarking suite |
composer coverage |
Analyze test coverage |
composer build |
Full pipeline: install → analyze → test → check |
Namespace Rubix\ML autoloaded from src/.
src/ → Rubix\ML\* (PSR-4)
tests/ → Rubix\ML\Tests\* (PHPUnit, mirrors src/)
benchmarks/ → Rubix\ML\Benchmarks\* (PHPBench, mirrors src/)
docs/ → MkDocs documentation
Estimator, Learner, Online, Iterative, Parallel, Probabilistic, Persistable, Verbose, RanksFeatures, Scoring
Rubix ML uses a high-level type system. Strings and integers are considered categorical and floats are considered continuous.
- Classifiers (15): AdaBoost, RandomForest, SVC, LogisticRegression, MLP, KNN, NaiveBayes, etc.
- Regressors (10): GradientBoost, Ridge, SVR, RegressionTree, Adaline, KNNRegressor, etc.
- Clusterers (5): KMeans, DBSCAN, GaussianMixture, MeanShift, FuzzyCMeans
- Anomaly Detectors (7): IsolationForest, LOF, OneClassSVM, GaussianMLE, Loda, RobustZScore
- PSR-2 with extended rules (enforced by PHP-CS-Fixer, see
.php-cs-fixer.dist.php) - DocBlock on every class, property, method, constant, and function
- No anonymous classes or functions (breaks serialization/persistence)
- Objects are generally immutable — state mutation only through a well-defined public API
- Domain-driven naming — names reflect the ML domain
- No inline comments — use expressive syntax and abstractions instead
- Single quotes for strings, short array syntax (
[]) - Prefer pre-increment (
++$i) over post-increment where possible - No superfluous
else/returnconstructs - Bugfixes should include a test that reproduces the bug before the fix
- Optimizations should include a before and after benchmark
- Include documentation updates for changes that effect the public API
- Class members annotated
internalare not part of the public API - Verify changes by running tests, static analysis, and code style fixer
- Create class in
src/Classifiers/,src/Regressors/,src/AnomalyDetectors/, orsrc/Clusterers/ - Implement the appropriate interface(s) —
Estimator+Learner(orOnline) at minimum - Create PHPUnit test in
tests/with#[CoversClass]attribute - For learners: end-to-end test — generate synthetic data, train, validate against minimum score; seed the RNG for determinism
- Create benchmark in
benchmarks/ - Run
composer analyze && composer test && composer fix - Add documentation page under
docs/
- Create class in
src/Transformers/implementing theTransformerinterface - Create PHPUnit test in
tests/Transformers/ - Add documentation page under
docs/transformers/
- Layers →
src/NeuralNet/Layers/ - Activation functions →
src/NeuralNet/ActivationFunctions/ - Cost functions →
src/NeuralNet/CostFunctions/ - Optimizers →
src/NeuralNet/Optimizers/ - Initializers →
src/NeuralNet/Initializers/
pip install mike mkdocs mkdocs-material mkdocs-git-revision-date-localized-plugin
mike deploy 'VERSION'
mike serveGitHub Actions (.github/workflows/ci.yml) runs on push/PR: phpstan → phpunit → php-cs-fixer check.