RegressorPipeline#

class capymoa.stream.preprocessing.RegressorPipeline[source]#

Bases: BasePipeline, Regressor

Regressor pipeline that (in addition to the functionality of BasePipeline) also acts as a regressor.

__init__(
pipeline_elements: list[PipelineElement] | None = None,
schema: Schema | None = None,
random_seed: int = 1,
validate_schema: bool = True,
)[source]#

Initializes the base pipeline with a list of pipeline elements.

Parameters#

pipeline_elements: List[PipelineElement]

The elements the pipeline consists of

schema: Optional[Schema]

The schema of instances entering the pipeline. Normally left unset, in which case it is taken from the first element that knows one.

random_seed: int

Seed reported to satisfy the learner interface. The pipeline does not draw from it; its elements carry their own seeds.

validate_schema: bool

If True, adding an element whose schema is incompatible with the schema leaving the pipeline raises a ValueError.

add_drift_detector(
drift_detector: BaseDriftDetector,
get_drift_detector_input_func: Callable,
)[source]#

Adds a drift detector to the end of the current pipeline

Parameters#

drift_detector: BaseDriftDetector

The drift_detector to add

get_drift_detector_input_func: Callable

The function that prepares the input of the drift detector. The function signature should start with the instance and the prediction. E.g., prediction_is_correct(instance, pred). The output of that function gets passed to the drift detector

Returns#

BasePipeline

self

add_pipeline_element(
element: PipelineElement,
)[source]#

Adds the provided pipeline element to the end of the pipeline

Parameters#

element: PipelineElement

The element to add to the pipeline

Returns#

BasePipeline

self

Raises#

ValueError

If the element’s schema is incompatible with the schema currently leaving the pipeline and validate_schema is enabled.

add_regressor(regressor: Regressor)[source]#

Adds a regressor to the end of the current pipeline

Parameters#

regressor: Regressor

The regressor to add to the pipeline

Returns#

RegressorPipeline

self

add_transformer(
transformer: Transformer,
)[source]#

Adds a transformer to the end of the current pipeline

Parameters#

transformer: Transformer

The transformer to add

Returns#

BasePipeline

self

classmethod from_params(
schema: Any = None,
params: dict[str, Any] | None = None,
random_seed: int = 1,
) → Any[source]#

Construct an instance from parameters produced by get_params.

get_input_schema() → Schema | None[source]#

Return the schema of instances entering the pipeline.

This is the schema of the first element that knows one, unless it was given explicitly at construction.

get_params() → dict[str, Any][source]#

Return the hyper-parameters captured from the constructor.

get_schema() → Schema | None[source]#

Return the schema of instances leaving the pipeline.

This is the schema of the last element that knows one, so a pipeline nested inside another reports what its own last element produces. Falls back to the input schema when no element alters it, and is None for an empty pipeline with no declared schema.

pass_forward(
instance: Instance,
) → Instance[source]#

Passes the instance through the pipeline and returns it. This transforms the instance depending on the transformers in the pipeline

Parameters#

instance: Instance

The instance

Returns#

Instance

The instance that exits the pipeline

pass_forward_predict(
instance: Instance,
prediction: Any = None,
) → tuple[Instance, Any][source]#

Passes the instance through the pipeline and returns it. Also returns the prediction of the pipeline.

Parameters#

instance: Instance

The input instance

prediction: Any

The prediction passed to the pipeline. This can be useful to, e.g., set up a change detection pipeline after the prediction pipeline

Returns#

Tuple[Instance, Any]

The instance that exits the pipeline and the prediction that exits the pipeline. In the case of a BasePipeline, this is most likely the prediction that was given to the function

predict(instance: Instance) → float64[source]#

The predict function of the regressor. Calls pass_forward_predict internally and returns the prediction.

Parameters#

instance: Instance

The instance to predict

Returns#

TargetValue

The prediction of the pipeline

train(instance: RegressionInstance)[source]#

The train function of the Regressor. Calls pass_forward internally.

Parameters#

instance: RegressionInstance

The instance to train on

property schema: Schema | None#

The schema of instances the pipeline consumes.

This is the input schema, because that is what capymoa.base.Classifier and capymoa.base.Regressor mean by schema: the instances handed to train and predict. What the pipeline emits downstream may differ, and is reported by get_schema().

Defined as a property so that it keeps up with elements added after construction.