Skip to content

StackingClassifier

Stacking for binary classification.

Parameters

  • models

    Typelist[base.Classifier]

  • meta_classifier

    Typebase.Classifier

  • include_features

    DefaultTrue

    Indicates whether or not the original features should be provided to the meta-model along with the predictions from each model.

Attributes

  • models

Examples

from river import compose
from river import datasets
from river import ensemble
from river import evaluate
from river import linear_model as lm
from river import metrics
from river import preprocessing as pp

dataset = datasets.Phishing()

model = compose.Pipeline(
    ('scale', pp.StandardScaler()),
    ('stack', ensemble.StackingClassifier(
        [
            lm.LogisticRegression(),
            lm.PAClassifier(mode=1, C=0.01),
            lm.PAClassifier(mode=2, C=0.01),
        ],
        meta_classifier=lm.LogisticRegression()
    ))
)

metric = metrics.F1()

evaluate.progressive_val_score(dataset, model, metric)
F1: 88.14%

Methods

learn_one

Update the model with a set of features x and a label y.

Parameters

  • x
  • y

predict_one

Predict the label of a set of features x.

Parameters

  • x'dict'
  • kwargs

Returns

base.typing.ClfTarget | None: The predicted label.

predict_proba_one

Predict the probability of each label for a dictionary of features x.

Parameters

  • x

Returns

A dictionary that associates a probability which each label.