ClassifierPipeline#
- class capymoa.stream.preprocessing.ClassifierPipeline[source]#
Bases:
BasePipeline,ClassifierClassifier pipeline that (in addition to the functionality of BasePipeline) also acts as a classifier.
- __init__(
- pipeline_elements: list[PipelineElement] | None = None,
- schema: Schema | None = None,
- random_seed: int = 1,
- validate_schema: bool = True,
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_classifier(classifier: Classifier)[source]#
Adds a classifier to the end of the current pipeline
Parameters#
- classifier: Classifier
The classifier to add to the pipeline
Returns#
- ClassifierPipeline
self
- add_drift_detector(
- drift_detector: BaseDriftDetector,
- get_drift_detector_input_func: Callable,
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,
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_schemais enabled.
- add_transformer(
- transformer: Transformer,
Adds a transformer to the end of the current pipeline
Parameters#
- transformer: Transformer
The transformer to add
Returns#
- BasePipeline
self
- classmethod from_params( ) 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_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
Nonefor an empty pipeline with no declared schema.
- pass_forward(
- instance: Instance,
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( ) 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) int | None[source]#
The predict function of the classifier. Calls pass_forward_predict internally and returns the prediction.
Parameters#
- instance: Instance
The instance to predict
Returns#
- Optional[LabelIndex]
The prediction of the pipeline
- predict_proba(
- instance: Instance,
Return probability estimates for each label.
- Parameters:
instance – The instance to estimate the probabilities for.
- Returns:
An array of probabilities for each label or
Noneif the classifier is unable to make a prediction.
- train(instance: LabeledInstance)[source]#
The train function of the Classifier. Calls pass_forward internally.
Parameters#
- instance: LabeledInstance
The instance to train on
- random_seed: int#
The random seed for reproducibility.
When implementing a classifier ensure random number generators are seeded.
- property schema: Schema | None#
The schema of instances the pipeline consumes.
This is the input schema, because that is what
capymoa.base.Classifierandcapymoa.base.Regressormean byschema: the instances handed totrainandpredict. What the pipeline emits downstream may differ, and is reported byget_schema().Defined as a property so that it keeps up with elements added after construction.