Open source · MIT licensed

Machine Learning
for PHP

A high-level machine learning and deep learning library for the PHP language. Build programs that learn from your data — from ETL to training, cross-validation, and production.

composer require rubix/ml
  • 40+ algorithms
  • ETL & preprocessing
  • Cross-validation
  • Parallel backends

01 — The toolbox

40+ learning algorithms, ready to train

Supervised and unsupervised estimators for classification, regression, clustering, and anomaly detection — all behind one consistent, delightful API.

0 Classifiers
0 Regressors
0 Clusterers
0 Anomaly Detectors
0 Dimensionality Reduction

02 — End-to-end

From raw data to a trained model

Rubix ML covers the entire machine learning life cycle. Extract data from any source, clean and transform it through composable pipelines, train your estimator, then cross-validate and ship it to production.

  • AutoML & hyper-parameter tuning with Grid Search
  • Cross-validation with Hold Out, K-Fold, and Monte Carlo
  • Ensembles, committee machines, and model persistence
Extract
Transform
Train
Validate
Predict

Preprocessing

Standardize, normalize, impute, and discretize your features with robust transformers.

Z Scale StandardizerMin Max NormalizerMissing Data ImputerInterval Discretizer

Text & NLP

Vectorize text into numeric feature bags with tokenizers and TF-IDF weighting.

Word Count VectorizerTF-IDF TransformerStop Word FilterBM25 Transformer

Images

Resize, flip, rotate, and vectorize images for computer vision tasks.

Image ResizerImage VectorizerImage RotatorColor Jitter

Dimensionality Reduction

Project high-dimensional data into compact embeddings for speed and clarity.

PCAt-SNETruncated SVDRandom Projector

03 — Deep learning

Build neural networks layer by layer

A full deep learning engine with feed-forward networks, backpropagation, and a rich library of layers, activation functions, cost functions, and optimizers.

Everything you need to go deep

Hidden Layers

  • Dense
  • Activation
  • Dropout
  • Batch Norm
  • PReLU & Swish
  • Noise

Activations

  • ReLU & variants
  • Sigmoid
  • Hyperbolic Tangent
  • GELU / SiLU
  • SELU / ELU
  • Softmax

Cost Functions

  • Cross Entropy
  • Least Squares
  • Huber Loss
  • Relative Entropy

Optimizers

  • Adam & Adamax
  • Momentum
  • RMS Prop
  • AdaGrad
  • Stochastic

Interval, cyclical, and step-decay learning rate schedulers included.

04 — Production

Validate, persist, and scale

Measure real performance with a complete suite of metrics and reports, save models to disk, and accelerate training with parallel processing backends.

Cross-Validation

Robust resampling strategies and 25+ metrics — accuracy, F1, MCC, RMSE, R², and more — plus confusion matrices and error analysis reports.

K-FoldHold OutMonte CarloLeave P Out

Model Persistence

Serialize trained models with the efficient RBX format, native PHP, or Gzip — then reload them anywhere, any time.

RBXNativeGzip Native

Parallel & Fast

Tap into multi-core processing with the Swoole or AMP backend, and compute tensors at native speed with the Tensor extension.

SwooleAMPSerialTensor Ext

05 — Delightful API

Train a model in a few lines

Expressive, object-oriented, and consistent. Here is a full workflow — build a dataset, train a learner, and make predictions.

classify.php
 1use Rubix\ML\Datasets\Labeled;
 2use Rubix\ML\Classifiers\KNearestNeighbors;
 3use Rubix\ML\CrossValidation\Metrics\Accuracy;
 4
 5// 1. Load a labeled dataset
 6$dataset = new Labeled($samples, $labels);
 7$dataset->randomize()->split(0.8);
 8
 9// 2. Choose and train an estimator
10$estimator = new KNearestNeighbors(3);
11$estimator->train($dataset);
12
13// 3. Make predictions on unknown samples
14$predictions = $estimator->predict($testing);
15
16// 4. Score the model
17$score = (new Accuracy())->score($testing->labels(), $predictions);

07 — FAQ

Questions, answered

Is Rubix ML free to use?

Yes. The code is licensed under the permissive MIT license and is free to use commercially. The documentation is licensed CC BY-NC 4.0.

What PHP version do I need?

PHP 8.3 or above. The Tensor extension is recommended for fast matrix and vector computing, and Swoole is optional for multiprocessing.

Do I need to know machine learning?

No. The library ships with a gentle introduction, a basic tutorial, and complete API docs. Beginners can learn as they build.

Can I use it in production?

Absolutely. Models are persistable, estimators are serializable, and the library supports cross-validation, parallel backends, and inference at scale.

Where can I get help?

Join the community on Telegram, browse the documentation, or open an issue on GitHub.

Join the community

Interact with maintainers and other PHP machine learning enthusiasts.

Telegram Channel Star on GitHub

Code: MIT  ·  Docs: CC BY-NC 4.0

Start building with Rubix ML

One command is all it takes to bring machine learning to your PHP project.

composer require rubix/ml