Skip to content


Transformers take Dataset objects and modify the features contained within. They are often used as part of a transformer Pipeline or they can be used on their own.

Transform a Dataset#

To transform a dataset, pass a transformer object to the apply() method on a Dataset object like in the example below.

use Rubix\ML\Transformers\MinMaxNormalizer;

$dataset->apply(new MinMaxNormalizer());

The transformer can directly transform the samples in place via the transform() method given a samples array:

public transform(array &$samples) : void



Stateful transformers are those that require fitting before they can transform. The fit() method takes a dataset as input and pre-computes any necessary information in order to carry out future transformations. You can think of fitting a transformer like training a learner.

Fit a Dataset#

To fit the transformer to a training set:

public fit(Dataset $dataset) : void

Check if the transformer has been fitted:

public fitted() : bool

use Rubix\ML\Transformers\OneHotEncoder;

$transformer = new OneHotEncoder();



To apply a Stateful transformer to a dataset object, pass the transformer instance to the apply() method like you normally would. The transformer will automatically be fitted with the dataset before transforming the samples.

use Rubix\ML\Transformers\OneHotEncoder;

$dataset->apply(new OneHotEncoder());


Some transformers are able to adapt to new training data. The update() method provided by the Elastic interface can be used to modify the fitting of the transformer with new data even after being previously fitted. Updating is the transformer equivalent to partially training an Online learner.

Update a Fitting#

public update(Dataset $dataset) : void
use Rubix\ML\Transformers\ZScaleStandardizer;

$transformer = new ZScaleStandardizer();

$folds = $dataset->fold(3);





Transformers that implement the Reversible interface can reverse the transformation applied to a dataset. To apply the reverse transform to a dataset call the reverseApply() method on the dataset object and pass it the reversible transformer.

$transformer = new ZScaleStandardizer();


// Do something