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.

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

Base class for callback steps.

class neuraxle.steps.misc.CallbackWrapper(wrapped, transform_callback_function, fit_callback_function, inverse_transform_callback_function=None, more_arguments: List[T] = (), hyperparams=None)[source]

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)
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

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

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

class neuraxle.steps.misc.FitTransformCallbackStep(transform_callback_function=None, fit_callback_function=None, more_arguments: List[T] = (), transform_function=None, hyperparams=None)[source]
clear_callbacks()[source]
fit(data_inputs, expected_outputs=None)[source]

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

Parameters
  • data_inputs – data inputs

  • expected_outputs – expected outputs to fit on

Returns

fitted self

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

transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

class neuraxle.steps.misc.HandleCallbackStep(handle_fit_callback, handle_transform_callback, handle_fit_transform_callback)[source]
class neuraxle.steps.misc.Sleep(sleep_time=0.1, hyperparams=None, hyperparams_space=None)[source]
transform(data_inputs)[source]

Transform given data inputs.

Parameters

data_inputs – data inputs

Returns

transformed data inputs

class neuraxle.steps.misc.TapeCallbackFunction[source]

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()
callback(data, name: str = '')[source]

Will stick the data and name to the tape.

Parameters
  • data – data to save

  • name – name to save (string)

Returns

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.

reset()[source]

Reset callback data. :return: None

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

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)

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).

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).