neuraxle.steps.numpy¶
Module-level documentation for neuraxle.steps.numpy. Here is an inheritance diagram, including dependencies to other base modules of Neuraxle:
Pipeline Steps Based on NumPy¶
Those steps works with NumPy (np) arrays.
Classes
|
Step to add a scalar to a numpy array. |
|
Step to multiply a numpy array. |
|
Compute np.abs. |
|
Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.argmax.html>̀_ at the given axis. |
Numpy concatenation step where the concatenation is performed along axis=-1. |
|
|
Numpy concetenation step where the concatenation is performed along the specified custom axis. |
Numpy concatenation step where the concatenation is performed along the specified custom axis. |
|
Numpy concetenation step where the concatenation is performed along axis=0. |
|
|
Compute time series FFT using np.fft.rfft |
|
Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.max.html>̀_ at the given axis. |
|
Compute np.mean at the given axis. |
|
Compute np.median at the given axis. |
|
Compute np.min at the given axis. |
Return a contiguous flattened array using `np.ravel <https://numpy.org/doc/stable/reference/generated/numpy.ravel.html>̀_ |
|
|
Reshape numpy array in data inputs. |
|
|
|
|
|
Step to one hot a set of columns. |
|
Step sum numpy array using np.sum. |
|
Convert data inputs to a list. |
|
Convert data inputs, and expected outputs to a numpy array. |
Examples using neuraxle.steps.numpy.MultiplyByN
¶
Examples using neuraxle.steps.numpy.NumpyRavel
¶
Examples using neuraxle.steps.numpy.NumpyShapePrinter
¶
Examples using neuraxle.steps.numpy.NumpyTranspose
¶
-
class
neuraxle.steps.numpy.
NumpyFlattenDatum
[source]¶ Bases:
neuraxle.base.BaseTransformer
-
transform
(data_inputs)[source]¶ Transform given data inputs.
- Parameters
data_inputs – data inputs
- Returns
transformed data inputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyConcatenateOnAxis
(axis)[source]¶ Bases:
neuraxle.base.BaseTransformer
Numpy concetenation step where the concatenation is performed along the specified custom axis.
-
__init__
(axis)[source]¶ Create a numpy concatenate on custom axis object. :param axis: the axis where the concatenation is performed. :return: NumpyConcatenateOnAxis instance.
-
_transform_data_container
(data_container, context)[source]¶ Handle transform.
- Parameters
data_container – the data container to join
context – execution context
- Returns
transformed data container
-
transform
(data_inputs)[source]¶ Apply the concatenation transformation along the specified axis. :param data_inputs: :return: Numpy array
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyConcatenateOnAxisIfNotEmpty
(axis)[source]¶ Bases:
neuraxle.base.BaseTransformer
Numpy concatenation step where the concatenation is performed along the specified custom axis.
-
__init__
(axis)[source]¶ Create a numpy concatenate on custom axis object. :param axis: the axis where the concatenation is performed. :return: NumpyConcatenateOnAxis instance.
-
_transform_data_container
(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext)[source]¶ Handle transform.
- Parameters
data_container (
DataContainer
) – the data container to joincontext (
ExecutionContext
) – execution context
- Returns
transformed data container
-
transform
(data_inputs)[source]¶ Apply the concatenation transformation along the specified axis. :param data_inputs: :return: Numpy array
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyConcatenateInnerFeatures
[source]¶ Bases:
neuraxle.steps.numpy.NumpyConcatenateOnAxis
Numpy concatenation step where the concatenation is performed along axis=-1.
-
__init__
()[source]¶ Create a numpy concatenate inner features object. :return: NumpyConcatenateOnAxis instance.
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyConcatenateOuterBatch
[source]¶ Bases:
neuraxle.steps.numpy.NumpyConcatenateOnAxis
Numpy concetenation step where the concatenation is performed along axis=0.
-
__init__
()[source]¶ Create a numpy concatenate outer batch object. :return: NumpyConcatenateOnAxis instance which is inherited by base step.
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyTranspose
(axes: Sequence[int] = None)[source]¶ Bases:
neuraxle.base.BaseTransformer
-
__init__
(axes: Sequence[int] = None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
_transform_data_container
(data_container, context)[source]¶ Handle transform.
- Parameters
data_container – the data container to join
context – execution context
- Returns
transformed data container
-
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.
p = Pipeline([MultiplyByN(2)]) _in = np.array([1, 2]) _out = p.transform(_in) _regenerated_in = p.inverse_transform(_out) assert np.array_equal(_regenerated_in, _in) assert np.array_equal(_out, _in * 2)
- Parameters
processed_outputs – processed data inputs
- Returns
inverse transformed processed outputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyShapePrinter
(custom_message: str = '')[source]¶ Bases:
neuraxle.base.BaseTransformer
-
__init__
(custom_message: str = '')[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
-
inverse_transform
(processed_outputs)[source]¶ Inverse Transform the given transformed data inputs.
p = Pipeline([MultiplyByN(2)]) _in = np.array([1, 2]) _out = p.transform(_in) _regenerated_in = p.inverse_transform(_out) assert np.array_equal(_regenerated_in, _in) assert np.array_equal(_out, _in * 2)
- Parameters
processed_outputs – processed data inputs
- Returns
inverse transformed processed outputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
MultiplyByN
(multiply_by: int = 1)[source]¶ Bases:
neuraxle.base.BaseTransformer
Step to multiply a numpy array. Accepts an integer for the number to multiply by.
Example usage:
pipeline = Pipeline([ MultiplyByN(3) ]) outputs = pipeline.transform(np.array([1]) # outputs => np.array([3])
See also
-
__init__
(multiply_by: int = 1)[source]¶ Initialize self. See help(type(self)) for accurate signature.
-
with_hp_range
(multiply_by_hp_range: range) → neuraxle.steps.numpy.MultiplyByN[source]¶ Specify a range for the hyperparametern “N” to be used as an hyperparameter space.
- Parameters
hp_range – range of the hyperparameter. E.g.:
range(1, 10)
-
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.
p = Pipeline([MultiplyByN(2)]) _in = np.array([1, 2]) _out = p.transform(_in) _regenerated_in = p.inverse_transform(_out) assert np.array_equal(_regenerated_in, _in) assert np.array_equal(_out, _in * 2)
- Parameters
processed_outputs – processed data inputs
- Returns
inverse transformed processed outputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
AddN
(add=1)[source]¶ Bases:
neuraxle.base.BaseTransformer
Step to add a scalar to a numpy array. Accepts an integer for the number to add to every data inputs.
Example usage:
pipeline = Pipeline([ AddN(1) ]) outputs = pipeline.transform(np.array([1]) # outputs => np.array([2])
See also
-
with_hp_range
(hp_range: Iterable[Union[float, int]]) → neuraxle.steps.numpy.AddN[source]¶ Specify a range for the hyperparametern “N” to be used as an hyperparameter space.
- Parameters
hp_range – range of the hyperparameter. E.g.:
range(1, 10)
-
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.
p = Pipeline([MultiplyByN(2)]) _in = np.array([1, 2]) _out = p.transform(_in) _regenerated_in = p.inverse_transform(_out) assert np.array_equal(_regenerated_in, _in) assert np.array_equal(_out, _in * 2)
- Parameters
processed_outputs – processed data inputs
- Returns
inverse transformed processed outputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
Sum
(axis)[source]¶ Bases:
neuraxle.base.BaseTransformer
Step sum numpy array using np.sum.
Example usage:
pipeline = Pipeline([ Sum(axis=-1) ]) outputs = pipeline.transform(np.array([1, 2, 3]) # outputs => 6)
See also
BaseStep
-
transform
(data_inputs)[source]¶ Transform given data inputs.
- Parameters
data_inputs – data inputs
- Returns
transformed data inputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
OneHotEncoder
(nb_columns, name)[source]¶ Bases:
neuraxle.base.BaseTransformer
Step to one hot a set of columns. Accepts Integer Columns and converts it ot a one_hot. Rounds floats to integer for safety in the transform.
Example usage:
Set up data
import numpy as np a = np.array([1,0,3]) b = np.array([[0,1,0,0], [1,0,0,0], [0,0,0,1]])
Do the actual conversion
from neuraxle.steps.numpy import OneHotEncoder encoder = OneHotEncoder(nb_columns=4) b_pred = encoder.transform(a)
Assert it works
assert b_pred == b
-
transform
(data_inputs)[source]¶ Transform data inputs using one hot encoding, adding no_columns to the -1 axis. :param data_inputs: data inputs to encode :return: one hot encoded data inputs
-
_abc_impl
= <_abc_data object>¶
-
class
neuraxle.steps.numpy.
ToNumpy
[source]¶ Bases:
neuraxle.base.ForceHandleMixin
,neuraxle.base.BaseTransformer
Convert data inputs, and expected outputs to a numpy array.
-
_will_process
(data_container: neuraxle.data_container.DataContainer, context: neuraxle.base.ExecutionContext) → Tuple[neuraxle.data_container.DataContainer, neuraxle.base.ExecutionContext][source]¶ Apply side effects before any step method. :type context:
ExecutionContext
:type data_container:DataContainer
:param data_container: data container :param context: execution context :return: (data container, execution context)
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
ToList
[source]¶ Bases:
neuraxle.base.BaseTransformer
Convert data inputs to a list.
-
transform
(data_inputs)[source]¶ Transform data inputs, and expected outputs to a list. :param data_inputs: data inputs to convert :return: list of data inputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyReshape
(new_shape)[source]¶ Bases:
neuraxle.base.BaseTransformer
Reshape numpy array in data inputs.
import numpy as np a = np.array([1,0,3]) outputs = NumpyReshape(shape=(-1,1)).transform(a) assert np.array_equal(outputs, np.array([[1],[0],[3]]))
See also
BaseStep
-
transform
(data_inputs)[source]¶ Transform given data inputs.
- Parameters
data_inputs – data inputs
- Returns
transformed data inputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyRavel
[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Return a contiguous flattened array using `np.ravel <https://numpy.org/doc/stable/reference/generated/numpy.ravel.html>̀_
See also
-
transform
(data_inputs)[source]¶ Flatten numpy array using ̀np.ravel <https://numpy.org/doc/stable/reference/generated/numpy.ravel.html>`_
- Parameters
data_inputs –
- Returns
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyFFT
(axis=None)[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute time series FFT using np.fft.rfft
See also
-
transform
(data_inputs)[source]¶ Will featurize time series data with FFT using `np.fft.rfft <>̀_
- Parameters
data_inputs – time series data of 3D shape: [batch_size, time_steps, sensors_readings]
- Returns
featurized data is of 2D shape: [batch_size, n_features]
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyAbs
[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute np.abs.
See also
-
transform
(data_inputs)[source]¶ Will featurize data with a absolute value transformation.
- Parameters
data_inputs – data inputs
- Returns
absolute data inputs
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyMean
(axis=None)[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute np.mean at the given axis.
See also
-
transform
(data_inputs)[source]¶ Will featurize data with a mean.
- Parameters
data_inputs – data inputs
- Returns
data inputs mean for the given axis
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyMedian
(axis=None)[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute np.median at the given axis.
See also
-
transform
(data_inputs)[source]¶ Will featurize data with a median.
- Parameters
data_inputs – data inputs
- Returns
data inputs median for the given axis
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyMin
(axis=None)[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute np.min at the given axis.
See also
-
transform
(data_inputs)[source]¶ Will featurize data with a min.
- Parameters
data_inputs – data inputs
- Returns
min value for the given axis
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyMax
(axis=None)[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.max.html>̀_ at the given axis.
See also
-
transform
(data_inputs)[source]¶ Will featurize data with a max.
- Parameters
data_inputs – 3D time series of shape [batch_size, time_steps, sensors]
- Returns
max value for the given axis
-
_abc_impl
= <_abc_data object>¶
-
-
class
neuraxle.steps.numpy.
NumpyArgMax
(axis=None)[source]¶ Bases:
neuraxle.base.NonFittableMixin
,neuraxle.base.BaseStep
Compute `np.max <https://numpy.org/doc/1.18/reference/generated/numpy.ndarray.argmax.html>̀_ at the given axis.
See also
-
transform
(data_inputs)[source]¶ Will featurize data with a max.
- Parameters
data_inputs – 3D time series of shape [batch_size, time_steps, sensors]
- Returns
max value for the given axis
-
_abc_impl
= <_abc_data object>¶
-