Scikit-learn metaoptimizers

E.g.: for use with RandomizedSearchCV.



class neuraxle.metaopt.sklearn.MetaSKLearnWrapper(wrapped: MetaEstimatorMixin)[source]
fit(data_inputs, expected_outputs=None) → neuraxle.base.BaseStep[source]
fit_one(data_input, expected_output=None) → neuraxle.base.BaseStep[source]
fit_transform(data_inputs, expected_outputs=None) -> ('BaseStep', typing.Any)[source]
fit_transform_one(data_input, expected_output=None) -> ('BaseStep', typing.Any)[source]
get_best_model() → neuraxle.base.BaseStep[source]
get_hyperparams() →[source]
get_hyperparams_space(flat=False) →[source]
meta_fit(X_train, y_train, metastep: neuraxle.base.MetaStepMixin)[source]

Uses a meta optimization technique (AutoML) to find the best hyperparameters in the given hyperparameter space.

Usage: p = p.meta_fit(X_train, y_train, metastep=RandomSearch(n_iter=10, scoring_function=r2_score, higher_score_is_better=True))

Call .mutate(new_method="inverse_transform", method_to_assign_to="transform"), and the current estimator will become

  • X_train – data_inputs.

  • y_train – expected_outputs.

  • metastep – a metastep, that is, a step that can sift through the hyperparameter space of another estimator.


your best self.

mutate(new_method='inverse_transform', method_to_assign_to='transform', warn=True) → neuraxle.base.BaseStep[source]

Replace the “method_to_assign_to” method by the “new_method” method, IF the present object has no pending calls to .will_mutate_to() waiting to be applied. If there is a pending call, the pending call will override the methods specified in the present call. If the change fails (such as if the new_method doesn’t exist), then a warning is printed (optional). By default, there is no pending will_mutate_to call.

This could for example be useful within a pipeline to apply inverse_transform to every pipeline steps, or to assign predict_probas to predict, or to assign “inverse_transform” to “transform” to a reversed pipeline.

  • new_method – the method to replace transform with, if there is no pending will_mutate_to call.

  • method_to_assign_to – the method to which the new method will be assigned to, if there is no pending will_mutate_to call.

  • warn – (verbose) wheter or not to warn about the inexistence of the method.


self, a copy of self, or even perhaps a new or different BaseStep object.

reverse() → neuraxle.base.BaseStep[source]

The object will mutate itself such that the .transform method (and of all its underlying objects if applicable) be replaced by the .inverse_transform method.

Note: the reverse may fail if there is a pending mutate that was set earlier with .will_mutate_to.


a copy of self, reversed. Each contained object will also have been reversed if self is a pipeline.

set_hyperparams(hyperparams: → neuraxle.base.BaseStep[source]
set_hyperparams_space(hyperparams_space: → neuraxle.base.BaseStep[source]
set_step(step: neuraxle.base.BaseStep) → neuraxle.base.BaseStep[source]
tosklearn() → NeuraxleToSKLearnPipelineWrapper[source]
will_mutate_to(new_base_step: Optional[neuraxle.base.BaseStep] = None, new_method: str = None, method_to_assign_to: str = None) → neuraxle.base.BaseStep[source]

This will change the behavior of self.mutate(<...>) such that when mutating, it will return the presently provided new_base_step BaseStep (can be left to None for self), and the .mutate method will also apply the new_method and the method_to_affect, if they are not None, and after changing the object to new_base_step.

This can be useful if your pipeline requires unsupervised pretraining. For example:

X_pretrain = ...
X_train = ...

p = Pipeline(
# Pre-train the pipeline
p =, y=None)

# This will leave `SomePreprocessing()` untouched and will affect the two other steps.
p = p.mutate(new_method="transform", method_to_affect="transform")

# Pre-train the pipeline
p =, y_train)  # Then fit the classifier and other new things
  • new_base_step – if it is not None, upon calling mutate, the object it will mutate to will be this provided new_base_step.

  • method_to_assign_to – if it is not None, upon calling mutate, the method_to_affect will be the one that is used on the provided new_base_step.

  • new_method – if it is not None, upon calling mutate, the new_method will be the one that is used on the provided new_base_step.