Step¶
-
class
baikal.Step(*args, name=None, n_outputs=1, **kwargs)¶ Bases:
baikal._core.step._StepBaseMixin 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 (DataPlaceholderobjects) of previous steps and optional targets (alsoDataPlaceholderobjects). 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_funcargument).
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_funcGet the compute function of the step.
fit_compute_funcGet the fit-compute function of the step.
inputsGet the inputs of the step.
n_outputsGet the number of outputs the step produces.
nameGet the name of the step.
outputsGet the outputs of the step.
targetsGet the targets of the step.
trainableGet trainable flag of the step.