Step¶
-
class
baikal.
Step
(*args, name=None, n_outputs=1, **kwargs)¶ Bases:
baikal._core.step._StepBase
Mixin class to endow scikit-learn classes with Step capabilities.
Steps are defined by combining any class we would like to make a step from with this mixin class. This mixin, among other things, endows the class of interest with a
__call__
method, making the class callable on the outputs (DataPlaceholder
objects) of previous steps and optional targets (alsoDataPlaceholder
objects). You can make a step from any class you like, so long that class implements the scikit-learn API.- Instructions:
Define a class that inherits from both this mixin and the class you wish to make a step of (in that order!).
In the class
__init__
, callsuper().__init__(...)
and pass the appropriate step parameters.
The base class may implement a predict/transform method (the compute function) that take multiple inputs and returns multiple outputs, and a fit method that takes multiple inputs and targets. In this case, the input/target arguments are expected to be a list of (typically) array-like objects, and the compute function is expected to return a list of array-like objects.
- Parameters
name – Name of the step (optional). If no name is passed, a name will be automatically generated.
n_outputs – The number of outputs of the step’s function (predict, transform, or any other callable passed in the
compute_func
argument).
Examples
import sklearn.linear_model # The order of inheritance is important! class LogisticRegression(Step, sklearn.linear_model.LogisticRegression): def __init__(self, *args, name=None, **kwargs): super().__init__(*args, name=name, **kwargs) logreg = LogisticRegression(C=2.0)
Methods
get_compute_func_at
(port)Get compute function at the specified port.
get_fit_compute_func_at
(port)Get fit-compute function at the specified port.
get_inputs_at
(port)Get inputs at the specified port.
get_outputs_at
(port)Get outputs at the specified port.
get_targets_at
(port)Get targets at the specified port.
get_trainable_at
(port)Get trainable flag at the specified port.
set_compute_func_at
(port, value)Set compute function at the specified port.
set_fit_compute_func_at
(port, value)Set fit-compute function at the specified port.
set_trainable_at
(port, value)Set trainable flag at the specified port.
__call__
(inputs[, targets, compute_func, …])Call the step on input(s) (from previous steps) and generates the output(s) to be used in further steps.
Attributes
compute_func
Get the compute function of the step.
fit_compute_func
Get the fit-compute function of the step.
inputs
Get the inputs of the step.
n_outputs
Get the number of outputs the step produces.
name
Get the name of the step.
outputs
Get the outputs of the step.
targets
Get the targets of the step.
trainable
Get trainable flag of the step.