module 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.
Classes#
class |
truncated documentation |
---|---|
Un transform qui cache plusieurs learners, arrangés selon la méthode du stacking. … |
Methods#
method |
truncated documentation |
---|---|
usual |
|
Trains a model. |
|
Returns the parameters which define the object. It follows scikit-learn API. |
|
Sets the parameters. |
|
Calls the learners predictions to convert the features. |
Documentation#
Implémente un transform qui suit la même API que tout scikit-learn transform.
- 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]]
- 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 thenpredict
.- __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 thenpredict
.
- __repr__()#
usual
- fit(X, y=None, **kwargs)#
Trains a model.
- Parameters:
X – features
y – targets
kwargs – additional parameters
- Returns:
self
- get_params(deep=True)#
Returns the parameters which define the object. It follows scikit-learn API.
- Parameters:
deep – unused here
- Returns:
dict
- set_params(**values)#
Sets the parameters.
- Parameters:
params – parameters
- transform(X)#
Calls the learners predictions to convert the features.
- Parameters:
X – features
- Returns:
prédictions