Medie

Metodi Ensemble in Python

Román de las Heras

Data Scientist, Appodeal

Contare le gelatine

Indovina le gelatine al festival delle bacche

Come dare una buona stima?

  • Indovinare (numero a caso)
  • Approssimare il volume
  • Molti altri approcci

Valore reale ~ media(stime)

Metodi Ensemble in Python

Media (Soft Voting)

Proprietà

  • Problemi di classificazione e regressione
  • Soft Voting: media
    • Regressione: media dei valori predetti
    • Classificazione: media delle probabilità predette
  • Servono almeno 2 stimatori
Metodi Ensemble in Python

Ensemble a media con scikit-learn

Averaging Classifier

from sklearn.ensemble import VotingClassifier

clf_voting = VotingClassifier( estimators=[ ('label1', clf_1), ('label2', clf_2), ... ('labelN', clf_N)], voting='soft', weights=[w_1, w_2, ..., w_N] )

Averaging Regressor

from sklearn.ensemble import VotingRegressor

reg_voting = VotingRegressor( estimators=[ ('label1', reg_1), ('label2', reg_2), ... ('labelN', reg_N)], weights=[w_1, w_2, ..., w_N] )
Metodi Ensemble in Python

Esempio scikit-learn

# Instantiate the individual models
clf_knn = KNeighborsClassifier(5)
clf_dt = DecisionTreeClassifier()
clf_lr = LogisticRegression()
# Create an averaging classifier
clf_voting = VotingClassifier(
    estimators=[
       ('knn', clf_knn), 
       ('dt', clf_dt), 
       ('lr', clf_lr)],
    voting='soft',
    weights=[1, 2, 1]
)
Metodi Ensemble in Python

Morti in Game of Thrones

Target:

  • Predire se un personaggio è vivo o no

Feature:

  • Età
  • Genere
  • Libri in cui appare
  • Popolarità
  • Se i parenti sono vivi o no

shutterstock_1038048793.jpg

Metodi Ensemble in Python

È il momento di esercitarsi!

Metodi Ensemble in Python

Preparing Video For Download...