Skip to content

model

SupportsPredict

Bases: Protocol

Protocol describing an object that has a predict method.

SupportsPredictProba

Bases: Protocol

Protocol describing an object that has a predict_proba method.

SciKitModel(estimator, *, output_names, name=None)

Bases: Model

A model that wraps a scikit-learn estimator.

Initialize the model.

Parameters:

Name Type Description Default
estimator SupportsPredict

The scikit-learn estimator.

required
output_names Iterable[str]

The names of the output columns.

required
name str | None

The name of the model.

None
Source code in src/flowcean/sklearn/model.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def __init__(
    self,
    estimator: SupportsPredict,
    *,
    output_names: Iterable[str],
    name: str | None = None,
) -> None:
    """Initialize the model.

    Args:
        estimator: The scikit-learn estimator.
        output_names: The names of the output columns.
        name: The name of the model.
    """
    super().__init__()
    if name is None:
        name = estimator.__class__.__name__
    self._name = name
    self.estimator = estimator
    self.output_names = list(output_names)

SciKitClassifierModel(estimator, *, output_names, threshold=0.5, name=None)

Bases: SciKitModel

A SciKit model for classifiers with probability predictions.

Supports threshold-based predictions via the threshold attribute and exposes class probabilities via predict_proba. The estimator must implement predict_proba.

Initialize the classifier model.

Parameters:

Name Type Description Default
estimator SupportsPredict

The scikit-learn classifier (must support predict_proba).

required
output_names Iterable[str]

The names of the output columns.

required
threshold float

Decision threshold for the positive class (default: 0.5).

0.5
name str | None

The name of the model.

None
Source code in src/flowcean/sklearn/model.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(
    self,
    estimator: SupportsPredict,
    *,
    output_names: Iterable[str],
    threshold: float = 0.5,
    name: str | None = None,
) -> None:
    """Initialize the classifier model.

    Args:
        estimator: The scikit-learn classifier (must support
            ``predict_proba``).
        output_names: The names of the output columns.
        threshold: Decision threshold for the positive class
            (default: 0.5).
        name: The name of the model.
    """
    super().__init__(estimator, output_names=output_names, name=name)
    self.threshold = threshold

predict_proba(input_features)

Predict class probabilities, applying preprocessing transforms.

Parameters:

Name Type Description Default
input_features DataFrame | LazyFrame

The inputs for which to predict probabilities.

required

Returns:

Type Description
LazyFrame

The predicted probabilities for the positive class.

Source code in src/flowcean/sklearn/model.py
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def predict_proba(
    self,
    input_features: pl.DataFrame | pl.LazyFrame,
) -> pl.LazyFrame:
    """Predict class probabilities, applying preprocessing transforms.

    Args:
        input_features: The inputs for which to predict probabilities.

    Returns:
        The predicted probabilities for the positive class.
    """
    input_features = self.preprocess(input_features)
    return self._predict_proba(input_features)