neuraxle.steps.misc

Module-level documentation for neuraxle.steps.misc. Here is an inheritance diagram, including dependencies to other base modules of Neuraxle:

Inheritance diagram of neuraxle.steps.misc

Miscelaneous Pipeline Steps

You can find here misc. pipeline steps, for example, callbacks useful for debugging, and a step cloner.

Classes

BaseCallbackStep(callback_function, …[, …])

Base class for callback steps.

CallbackWrapper(wrapped, …[, …])

A step that calls a callback function for each of his methods : transform, fit, fit_transform, and even inverse_transform.

FitCallbackStep(callback_function, …[, …])

Call a callback method on fit.

FitTransformCallbackStep([…])

HandleCallbackStep(handle_fit_callback, …)

Sleep([sleep_time, hyperparams, …])

TapeCallbackFunction()

This class’s purpose is to be sent to the callback to accumulate information.

TransformCallbackStep(callback_function, …)

Call a callback method on transform and inverse transform.

Examples using neuraxle.steps.misc.Sleep


class neuraxle.steps.misc.BaseCallbackStep(callback_function, more_arguments: List[T] = (), hyperparams=None, fit_callback_function=None, transform_function=None)[source]

Bases: neuraxle.base.BaseStep, abc.ABC

Base class for callback steps.

__init__(callback_function, more_arguments: List[T] = (), hyperparams=None, fit_callback_function=None, transform_function=None)[source]

Create the callback step with a function and extra arguments to send to the function

Parameters
  • callback_function – The function that will be called on events.

  • more_arguments – Extra arguments that will be sent to the callback after the processed data (optional).

_fit_callback(data_inputs, expected_outputs)[source]

Will call the self.fit_callback_function() with the data being processed and the extra arguments specified. It has no other effect.

Parameters
  • data_inputs – data inputs to fit

  • expected_outputs – expected outputs to fit

Returns

self

_callback(data)[source]

Will call the self.callback_function() with the data being processed and the extra arguments specified. It has no other effect.

Parameters

data_inputs – the data to process

Returns

None

fit(data_inputs, expected_outputs=None)[source]

Fit data inputs on the given expected outputs.

Parameters
  • data_inputs – data inputs

  • expected_outputs – expected outputs to fit on.

Returns

self

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

inverse_transform(processed_outputs)[source]

Inverse Transform the given transformed data inputs.

mutate() or reverse() can be called to change the default transform behavior :

p = Pipeline([MultiplyBy()])
_in = np.array([1, 2])
_out = p.transform(_in)
_regenerated_in = reversed(p).transform(_out)
assert np.array_equal(_regenerated_in, _in)
Parameters

processed_outputs – processed data inputs

Returns

inverse transformed processed outputs

_abc_impl = <_abc_data object>
class neuraxle.steps.misc.FitCallbackStep(callback_function, more_arguments: List[T] = (), hyperparams=None, fit_callback_function=None, transform_function=None)[source]

Bases: neuraxle.steps.misc.BaseCallbackStep

Call a callback method on fit.

fit(data_inputs, expected_outputs=None) → neuraxle.steps.misc.FitCallbackStep[source]

Will call the self._callback() with the data being processed and the extra arguments specified. Note that here, the data to process is packed into a tuple of (data_inputs, expected_outputs). It has no other effect.

Parameters
  • data_inputs – the data to process

  • expected_outputs – the data to process

Returns

self

_abc_impl = <_abc_data object>
class neuraxle.steps.misc.TransformCallbackStep(callback_function, more_arguments: List[T] = (), hyperparams=None, fit_callback_function=None, transform_function=None)[source]

Bases: neuraxle.steps.misc.BaseCallbackStep

Call a callback method on transform and inverse transform.

fit_transform(data_inputs, expected_outputs=None) -> ('BaseStep', typing.Any)[source]

Fit, and transform step with the given data inputs, and expected outputs.

Parameters
  • data_inputs – data inputs

  • expected_outputs – expected outputs to fit on

Returns

(fitted self, tranformed data inputs)

transform(data_inputs)[source]

Will call the self._callback() with the data being processed and the extra arguments specified. It has no other effect.

Parameters

data_inputs – the data to process

Returns

the same data as input, unchanged (like the Identity class).

inverse_transform(processed_outputs)[source]

Will call the self._callback() with the data being processed and the extra arguments specified. It has no other effect.

Parameters

processed_outputs – the data to process

Returns

the same data as input, unchanged (like the Identity class).

_abc_impl = <_abc_data object>
class neuraxle.steps.misc.FitTransformCallbackStep(transform_callback_function=None, fit_callback_function=None, more_arguments: List[T] = (), transform_function=None, hyperparams=None)[source]

Bases: neuraxle.base.BaseStep

__init__(transform_callback_function=None, fit_callback_function=None, more_arguments: List[T] = (), transform_function=None, hyperparams=None)[source]

Initialize self. See help(type(self)) for accurate signature.

fit(data_inputs, expected_outputs=None)[source]

Fit data inputs on the given expected outputs.

Parameters
  • data_inputs – data inputs

  • expected_outputs – expected outputs to fit on.

Returns

self

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

fit_transform(data_inputs, expected_outputs=None) -> ('BaseStep', typing.Any)[source]

Fit, and transform step with the given data inputs, and expected outputs.

Parameters
  • data_inputs – data inputs

  • expected_outputs – expected outputs to fit on

Returns

(fitted self, tranformed data inputs)

inverse_transform(processed_outputs)[source]

Inverse Transform the given transformed data inputs.

mutate() or reverse() can be called to change the default transform behavior :

p = Pipeline([MultiplyBy()])
_in = np.array([1, 2])
_out = p.transform(_in)
_regenerated_in = reversed(p).transform(_out)
assert np.array_equal(_regenerated_in, _in)
Parameters

processed_outputs – processed data inputs

Returns

inverse transformed processed outputs

clear_callbacks()[source]
_abc_impl = <_abc_data object>
class neuraxle.steps.misc.CallbackWrapper(wrapped, transform_callback_function, fit_callback_function, inverse_transform_callback_function=None, more_arguments: List[T] = (), hyperparams=None)[source]

Bases: neuraxle.base.HandleOnlyMixin, neuraxle.base.MetaStep

A step that calls a callback function for each of his methods : transform, fit, fit_transform, and even inverse_transform. To be used with TapeCallbackFunction.

tape_fit = TapeCallbackFunction()
tape_transform = TapeCallbackFunction()
tape_inverse_transform = TapeCallbackFunction()

callback_wrapper = CallbackWrapper(MultiplyByN(2), tape_transform_preprocessing, tape_fit_preprocessing, tape_inverse_transform_preprocessing)
__init__(wrapped, transform_callback_function, fit_callback_function, inverse_transform_callback_function=None, more_arguments: List[T] = (), hyperparams=None)[source]

Initialize self. See help(type(self)) for accurate signature.

_fit_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) -> ('BaseStep', <class 'neuraxle.data_container.DataContainer'>)[source]
Parameters
Returns

step, data_container

Type

(BaseStep, DataContainer)

_fit_transform_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) -> ('BaseStep', <class 'neuraxle.data_container.DataContainer'>)[source]
Parameters
Returns

step, data_container

Type

(BaseStep, DataContainer)

_transform_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) → neuraxle.data_container.DataContainer[source]
Return type

DataContainer

Parameters
Returns

step, data_container

Type

DataContainer

handle_inverse_transform(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) → neuraxle.data_container.DataContainer[source]
Parameters
Returns

data container

Return type

DataContainer

_abc_impl = <_abc_data object>
class neuraxle.steps.misc.TapeCallbackFunction[source]

Bases: object

This class’s purpose is to be sent to the callback to accumulate information.

Example usage:

expected_tape = ["1", "2", "3", "a", "b", "4"]
tape = TapeCallbackFunction()

p = Pipeline([
    Identity(),
    TransformCallbackStep(tape.callback, ["1"]),
    TransformCallbackStep(tape.callback, ["2"]),
    TransformCallbackStep(tape.callback, ["3"]),
    AddFeatures([
        TransformCallbackStep(tape.callback, ["a"]),
        TransformCallbackStep(tape.callback, ["b"]),
    ]),
    TransformCallbackStep(tape.callback, ["4"]),
    Identity()
])
p.fit_transform(np.ones((1, 1)))

assert expected_tape == tape.get_name_tape()
__init__()[source]

Initialize the tape (cache lists).

callback(data, name: str = '')[source]

Will stick the data and name to the tape.

Parameters
  • data – data to save

  • name (str) – name to save (string)

Returns

None

reset()[source]

Reset callback data. :return: None

get_data() → List[T][source]

Get the data tape

Returns

The list of data.

get_name_tape() → List[str][source]

Get the data tape

Returns

The list of names.

class neuraxle.steps.misc.HandleCallbackStep(handle_fit_callback, handle_transform_callback, handle_fit_transform_callback)[source]

Bases: neuraxle.base.ForceHandleOnlyMixin, neuraxle.base.BaseStep

__init__(handle_fit_callback, handle_transform_callback, handle_fit_transform_callback)[source]

Initialize self. See help(type(self)) for accurate signature.

_fit_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) -> ('BaseStep', <class 'neuraxle.data_container.DataContainer'>)[source]

Fit data container.

Parameters
Returns

(fitted self, data container)

_transform_data_container(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) → neuraxle.data_container.DataContainer[source]

Transform data container.

Return type

DataContainer

Parameters
Returns

data container

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

Fit transform data container.

Parameters
Returns

(fitted self, data container)

_abc_impl = <_abc_data object>
class neuraxle.steps.misc.Sleep(sleep_time=0.1, hyperparams=None, hyperparams_space=None)[source]

Bases: neuraxle.base.BaseTransformer

__init__(sleep_time=0.1, hyperparams=None, hyperparams_space=None)[source]

Initialize self. See help(type(self)) for accurate signature.

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

_abc_impl = <_abc_data object>