neuraxle.metaopt.deprecated

Neuraxle’s Automatic Machine Learning Classes

All steps, and abstractions needed to build Automatic Machine Learning algorithms in Neuraxle. ..

Copyright 2019, Neuraxio Inc. Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Classes

AutoMLAlgorithm(hyperparameter_optimizer[, …])

Pipeline step that executes Automatic Machine Learning strategy.

AutoMLContainer(trials, …)

Data object for auto ml.

AutoMLSequentialWrapper(wrapped, …[, …])

A step to execute any Automatic Machine Learning Algorithms.

BaseCrossValidationWrapper([wrapped, …])

BaseHyperparameterOptimizer

HyperparamsJSONRepository(folder)

Hyperparams repository that saves json files for every AutoML trial.

HyperparamsRepository()

Hyperparams repository that saves hyperparams, and scores for every AutoML trial.

InMemoryHyperparamsRepository([…])

In memory hyperparams repository that can print information about trials.

KFoldCrossValidationWrapper([…])

RandomSearch(wrapped, hyperparams_repository)

Random Search Automatic Machine Learning Algorithm that randomly samples the space of random variables.

Trial(hyperparams, score, status)

Trials(trials)

Data object containing auto ml trials.

class neuraxle.metaopt.deprecated.AutoMLAlgorithm(hyperparameter_optimizer: neuraxle.metaopt.deprecated.BaseHyperparameterOptimizer, higher_score_is_better=True, cache_folder_when_no_handle=None)[source]

Pipeline step that executes Automatic Machine Learning strategy. It uses an hyperparameter optimizer of type BaseHyperparameterOptimizer to find the next best hyperparams. It uses a validation technique of type BaseCrossValidationWrapper to calculate the score. Please refer to AutoMLSequentialWrapper for a usage example.

See also

BaseCrossValidationWrapper, HyperparameterSamples, BaseHyperparameterOptimizer, BaseCrossValidationWrapper, TrialsContainer, HyperparameterSpace, MetaStepMixin, BaseStep

_abc_impl = <_abc_data object>
_fit_transform_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) -> ('BaseStep', <class 'neuraxle.data_container.DataContainer'>)[source]

Fit cross validation with wrapped step, and return the score.

Parameters
  • data_container – data container to fit transform

  • context – execution context

Returns

self, step score

Return type

(AutoMLAlgorithm, float)

find_next_best_hyperparams(auto_ml_container: neuraxle.metaopt.deprecated.AutoMLContainer) → neuraxle.hyperparams.space.HyperparameterSamples[source]

Find the next best hyperparams using previous trials.

Parameters

auto_ml_container (neuraxle.metaopt.new_automl.Trials) – trials data container

Returns

next best hyperparams

Return type

HyperparameterSamples

fit(data_inputs, expected_outputs=None)[source]

Using handle_fit(), fit step with the given data inputs, and expected outputs.

Parameters

data_inputs – data inputs

Returns

fitted self

get_best_hyperparams(trials: neuraxle.metaopt.deprecated.Trials) → neuraxle.hyperparams.space.HyperparameterSamples[source]

Get the best hyperparams from all previous trials.

Returns

best hyperparams

Return type

HyperparameterSamples

transform(data_inputs, expected_outputs=None)[source]

Using handle_transform(), transform data inputs.

Parameters

data_inputs – data inputs

Returns

outputs

class neuraxle.metaopt.deprecated.AutoMLContainer(trials: neuraxle.metaopt.deprecated.Trials, hyperparameter_space: neuraxle.hyperparams.space.HyperparameterSpace, trial_number: int)[source]

Data object for auto ml.

See also

Trainer, Trial, Trials, HyperparamsRepository, InMemoryHyperparamsRepository, HyperparamsJSONRepository, BaseHyperparameterSelectionStrategy, RandomSearchHyperparameterSelectionStrategy, HyperparameterSamples

class neuraxle.metaopt.deprecated.AutoMLSequentialWrapper(wrapped: neuraxle.base.BaseStep, auto_ml_algorithm: neuraxle.metaopt.deprecated.AutoMLAlgorithm, hyperparams_repository: neuraxle.metaopt.deprecated.HyperparamsRepository = None, n_iters: int = 100, refit=True, cache_folder_when_no_handle=None)[source]

A step to execute any Automatic Machine Learning Algorithms.

Example usage :

auto_ml: AutoMLSequentialWrapper = AutoMLSequentialWrapper(
    step=ForecastingPipeline(),
    auto_ml_algorithm=AutoMLAlgorithm(
        hyperparameter_optimizer=RandomSearchHyperparameterOptimizer(),
        validation_technique=KFoldCrossValidationWrapper(),
        higher_score_is_better=True
    ),
    hyperparams_repository=HyperparamsJSONRepository(),
    n_iters=100
)
auto_ml: AutoMLSequentialWrapper = auto_ml.fit(data_inputs, expected_outputs)
best_model: ForecastingPipeline = auto_ml.get_best_model()

See also

AutoMLAlgorithm, HyperparamsRepository, RandomSearch, BaseHyperparameterOptimizer, RandomSearchHyperparameterOptimizer, MetaStepMixin, NonTransformableMixin, BaseStep

_abc_impl = <_abc_data object>
_fit_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext)[source]

Find the best hyperparams using the wrapped AutoML strategy.

Parameters
Returns

fitted self

Return type

BaseStep

_fit_transform_data_container(data_container, context)[source]

Fit transform data container.

Parameters
  • data_container – data container

  • context – execution context

Returns

(fitted self, data container)

_load_auto_ml_data(trial_number: int) → neuraxle.metaopt.deprecated.AutoMLContainer[source]

Load data for all trials.

Parameters

trial_number (int) – trial number

Returns

auto ml data container

Return type

neuraxle.metaopt.new_automl.Trials

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

Get the best model from all of the previous trials. :return: best model step :rtype: BaseStep

_transform_data_container(data_container, context)[source]

Transform data container.

Parameters
  • data_container – data container

  • context – execution context

Returns

data container

get_best_model() → neuraxle.base.BaseStep[source]
set_step(step: neuraxle.base.BaseStep) → neuraxle.base.BaseStep[source]

Set wrapped step to the given step.

Parameters

step – new wrapped step

Returns

self

transform(data_inputs)[source]

Using handle_transform(), transform data inputs.

Parameters

data_inputs – data inputs

Returns

outputs

class neuraxle.metaopt.deprecated.BaseCrossValidationWrapper(wrapped=None, scoring_function=<function r2_score>, joiner=NumpyConcatenateOuterBatch( name=NumpyConcatenateOuterBatch, hyperparameters=HyperparameterSamples() ), cache_folder_when_no_handle=None, split_data_container_during_fit=True, predict_after_fit=True)[source]
_abc_impl = <_abc_data object>
_fit_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) → neuraxle.base.BaseStep[source]

Fit data container.

Parameters
  • data_container – data container

  • context – execution context

Returns

(fitted self, data container)

calculate_score(results)[source]
get_score()[source]
get_scores_std()[source]
split(data_inputs, expected_outputs)[source]
split_data_container(data_container: neuraxle.data_container.DataContainer) → Tuple[neuraxle.data_container.DataContainer, neuraxle.data_container.DataContainer][source]
train(train_data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext)[source]
class neuraxle.metaopt.deprecated.BaseHyperparameterOptimizer[source]
_abc_impl = <_abc_data object>
find_next_best_hyperparams(auto_ml_container: neuraxle.metaopt.deprecated.AutoMLContainer) → neuraxle.hyperparams.space.HyperparameterSamples[source]

Find the next best hyperparams using previous trials.

Parameters

auto_ml_container (neuraxle.metaopt.new_automl.Trials) – trials data container

Returns

next best hyperparams

Return type

HyperparameterSamples

class neuraxle.metaopt.deprecated.HyperparamsJSONRepository(folder)[source]

Hyperparams repository that saves json files for every AutoML trial.

See also

HyperparamsRepository, HyperparameterSamples, AutoMLSequentialWrapper

_abc_impl = <_abc_data object>
_create_trial_json(hyperparams)[source]

Save new trial json file.

Returns

(hyperparams, scores)

_get_new_trial_json_path(current_hyperparameters_hash)[source]
_remove_new_trial_json(current_hyperparameters_hash)[source]
_save_failed_trial_json(hyperparams, exception)[source]

Save trial json file.

Returns

(hyperparams, scores)

_save_successful_trial_json(hyperparams, score)[source]

Save trial json file.

Returns

(hyperparams, scores)

create_new_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples)[source]

Create new hyperperams trial json file.

Parameters

hyperparams (HyperparameterSamples) – hyperparams

Returns

load_all_trials(status: Optional[neuraxle.metaopt.trial.TRIAL_STATUS] = None) → neuraxle.metaopt.deprecated.Trials[source]

Load all hyperparameter trials with their corresponding score. Reads all the saved trial json files, sorted by creation date.

Returns

(hyperparams, scores)

save_failure_for_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, exception: Exception)[source]

Save hyperparams, and score for a failed trial.

Returns

(hyperparams, scores)

save_score_for_success_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, score: float)[source]

Save hyperparams, and score for a successful trial.

Returns

(hyperparams, scores)

class neuraxle.metaopt.deprecated.HyperparamsRepository[source]

Hyperparams repository that saves hyperparams, and scores for every AutoML trial.

See also

AutoMLSequentialWrapper AutoMLAlgorithm, BaseValidation, RandomSearchBaseAutoMLStrategy, HyperparameterSpace, HyperparameterSamples

_abc_impl = <_abc_data object>
_get_trial_hash(hp_dict)[source]
create_new_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples)[source]

Create new hyperperams trial.

Parameters

hyperparams (HyperparameterSamples) – hyperparams

Returns

load_all_trials(status: neuraxle.metaopt.trial.TRIAL_STATUS) → neuraxle.metaopt.deprecated.Trials[source]

Load all hyperparameter trials with their corresponding score. Sorted by creation date.

Returns

Trials (hyperparams, scores)

new_experiment(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples)[source]
save_failure_for_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, exception: Exception)[source]

Save hyperparams, and score for a failed trial.

Returns

(hyperparams, scores)

save_score_for_success_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, score: float)[source]

Save hyperparams, and score for a successful trial.

Returns

(hyperparams, scores)

class neuraxle.metaopt.deprecated.InMemoryHyperparamsRepository(print_new_trial=True, print_success_trial=True, print_exception=True, print_func: Callable = None)[source]

In memory hyperparams repository that can print information about trials. Useful for debugging.

Example usage :

InMemoryHyperparamsRepository(
    print_new_trial=True,
    print_success_trial=True,
    print_exception=True
)

See also

HyperparamsRepository, HyperparameterSamples, AutoMLSequentialWrapper

_abc_impl = <_abc_data object>
create_new_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples)[source]

Create new hyperperams trial.

Parameters

hyperparams (HyperparameterSamples) – hyperparams

Returns

load_all_trials(status: Optional[neuraxle.metaopt.trial.TRIAL_STATUS] = None) → neuraxle.metaopt.deprecated.Trials[source]

Load all hyperparameter trials with their corresponding score. Sorted by creation date.

Returns

Trials (hyperparams, scores)

save_failure_for_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, exception: Exception)[source]

Save hyperparams, and score for a failed trial.

Returns

(hyperparams, scores)

save_score_for_success_trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, score: float)[source]

Save hyperparams, and score for a successful trial.

Returns

(hyperparams, scores)

class neuraxle.metaopt.deprecated.KFoldCrossValidationWrapper(scoring_function=<function r2_score>, k_fold=3, joiner=NumpyConcatenateOuterBatch( name=NumpyConcatenateOuterBatch, hyperparameters=HyperparameterSamples() ), cache_folder_when_no_handle=None, split_data_container_during_fit=True, predict_after_fit=True)[source]
_abc_impl = <_abc_data object>
_split(data_inputs)[source]
split(data_inputs, expected_outputs)[source]
train_split(data_inputs, expected_outputs) -> (typing.List, typing.List)[source]
validation_split(data_inputs, expected_outputs=None) -> (typing.List, typing.List)[source]
class neuraxle.metaopt.deprecated.RandomSearch(wrapped: neuraxle.base.BaseStep = None, hyperparams_repository: neuraxle.metaopt.deprecated.HyperparamsRepository = None, higher_score_is_better=True, n_iter: int = 10, cache_folder_when_no_handle=None)[source]

Random Search Automatic Machine Learning Algorithm that randomly samples the space of random variables.

Example usage :

random_search = RandomSearch(
    ForecastingPipeline(),
    hyperparams_repository=HyperparamsJSONRepository(),
    n_iters=100
)
_abc_impl = <_abc_data object>
class neuraxle.metaopt.deprecated.Trial(hyperparams: neuraxle.hyperparams.space.HyperparameterSamples, score: float, status: neuraxle.metaopt.trial.TRIAL_STATUS)[source]
static from_json(trial_json) → neuraxle.metaopt.deprecated.Trial[source]
to_json() → dict[source]
class neuraxle.metaopt.deprecated.Trials(trials: List[neuraxle.metaopt.deprecated.Trial] = None)[source]

Data object containing auto ml trials. .. seealso:

:class:`AutoMLSequentialWrapper`,
:class:`RandomSearch`,
:class:`HyperparamsRepository`,
:class:`MetaStepMixin`,
:class:`BaseStep`
append(trial: neuraxle.metaopt.deprecated.Trial)[source]
filter(status: neuraxle.metaopt.trial.TRIAL_STATUS) → neuraxle.metaopt.deprecated.Trials[source]
get_best_hyperparams(higher_score_is_better: bool) → neuraxle.hyperparams.space.HyperparameterSamples[source]