module sklapi.sklearn_base_transform_stacking#

Inheritance diagram of mlinsights.sklapi.sklearn_base_transform_stacking

Short summary#

module mlinsights.sklapi.sklearn_base_transform_stacking

Implémente un transform qui suit la même API que tout scikit-learn transform.

source on GitHub

Classes#

class

truncated documentation

SkBaseTransformStacking

Un transform qui cache plusieurs learners, arrangés selon la méthode du stacking. …

Methods#

method

truncated documentation

__init__

__repr__

usual

fit

Trains a model.

get_params

Returns the parameters which define the object. It follows scikit-learn API.

set_params

Sets the parameters.

transform

Calls the learners predictions to convert the features.

Documentation#

Implémente un transform qui suit la même API que tout scikit-learn transform.

source on GitHub

class mlinsights.sklapi.sklearn_base_transform_stacking.SkBaseTransformStacking(models=None, method=None, **kwargs)#

Bases: SkBaseTransform

Un transform qui cache plusieurs learners, arrangés selon la méthode du stacking.

Stacking de plusieurs learners dans un pipeline scikit-learn.

Ce transform assemble les résultats de plusieurs learners. Ces features servent d’entrée à un modèle de stacking.

<<<

from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
from sklearn.pipeline import make_pipeline
from mlinsights.sklapi import SkBaseTransformStacking

data = load_iris()
X, y = data.data, data.target
X_train, X_test, y_train, y_test = train_test_split(X, y)

trans = SkBaseTransformStacking([LogisticRegression(),
                                 DecisionTreeClassifier()])
trans.fit(X_train, y_train)
pred = trans.transform(X_test)
print(pred[3:])

>>>

    [[0 0]
     [2 2]
     [0 0]
     [2 2]
     [1 1]
     [0 0]
     [1 1]
     [1 1]
     [2 2]
     [2 2]
     [1 1]
     [0 0]
     [2 2]
     [0 0]
     [2 1]
     [1 1]
     [2 1]
     [1 1]
     [0 0]
     [1 1]
     [0 0]
     [2 2]
     [0 0]
     [0 0]
     [0 0]
     [2 2]
     [1 1]
     [1 1]
     [1 1]
     [1 1]
     [0 0]
     [0 0]
     [2 2]
     [1 1]
     [2 1]]

source on GitHub

Parameters:
  • models – list of learners

  • method – methods or list of methods to call to convert features into prediction (see below)

  • kwargs – parameters

Available options for parameter method:

  • 'predict'

  • 'predict_proba'

  • 'decision_function'

  • a function

If method is None, the default value is first predict_proba it it exists then predict.

source on GitHub

__init__(models=None, method=None, **kwargs)#
Parameters:
  • models – list of learners

  • method – methods or list of methods to call to convert features into prediction (see below)

  • kwargs – parameters

Available options for parameter method:

  • 'predict'

  • 'predict_proba'

  • 'decision_function'

  • a function

If method is None, the default value is first predict_proba it it exists then predict.

source on GitHub

__repr__()#

usual

source on GitHub

fit(X, y=None, **kwargs)#

Trains a model.

Parameters:
  • X – features

  • y – targets

  • kwargs – additional parameters

Returns:

self

source on GitHub

get_params(deep=True)#

Returns the parameters which define the object. It follows scikit-learn API.

Parameters:

deep – unused here

Returns:

dict

source on GitHub

set_params(**values)#

Sets the parameters.

Parameters:

params – parameters

source on GitHub

transform(X)#

Calls the learners predictions to convert the features.

Parameters:

X – features

Returns:

prédictions

source on GitHub