Construiți primul ansamblu stivuit

Metode de ansamblu în Python

Román de las Heras

Data Scientist, Appodeal

Stivuirea modelelor cu scikit-learn

Caracteristici ale implementării stivuirii din scikit-learn:

  1. scikit-learn oferă estimatori pentru stivuire (începând cu versiunea 0.22)
  2. Compatibil cu alți estimatori scikit-learn
  3. Estimatorul final este antrenat prin validare încrucișată
Metode de ansamblu în Python

Pași generali

Pașii arhitecturii de stivuire

Pași generali de implementare:

  1. Pregătiți setul de date
  2. Construiți estimatorii din primul strat
  3. Adăugați predicțiile la setul de date
  4. Construiți meta-estimatorul din al doilea strat
  5. Utilizați ansamblul stivuit pentru predicții
Metode de ansamblu în Python

Clasificator stivuit

from sklearn.ensemble import StackingClassifier
# Instantiate the 1st-layer classifiers
classifiers = [
    ('clf1', Classifier1(params1)),
    ('clf2', Classifier2(params2)),
    ...
    ('clfN', ClassifierN(paramsN))
]
# Instantiate the 2nd-layer classifier
clf_meta = ClassifierMeta(paramsMeta)
# Build the Stacking classifier
clf_stack = StackingClassifier(
   estimators=classifiers,
   final_estimator=clf_meta,
   cv=5,
   stack_method='predict_proba',
   passthrough=False)
# Use the fit and predict methods
clf_stack.fit(X_train, y_train)
pred = clf_stack.predict(X_test)
Metode de ansamblu în Python

Regressor stivuit

from sklearn.ensemble import StackingRegressor
# Instantiate the 1st-layer regressors
regressors = [
    ('reg1', Regressor1(params1)),
    ('reg2', Regressor2(params2)),
    ...
    ('regN', RegressorN(paramsN))    
]
# Instantiate the 2nd-layer regressor
reg_meta = RegressorMeta(paramsMeta)
# Build the Stacking regressor
reg_stack = StackingRegressor(
   estimators=regressors,
   final_estimator=reg_meta,
   cv=5,
   passthrough=False)
# Use the fit and predict methods
reg_stack.fit(X_train, y_train)
pred = reg_stack.predict(X_test)
Metode de ansamblu în Python

Rândul dumneavoastră!

Metode de ansamblu în Python

Preparing Video For Download...