Voting Classifier
Ora combiniamo tre modelli di Machine Learning in uno per migliorare il nostro modello di rilevamento delle frodi con Random Forest visto prima. Unirai il solito modello Random Forest, la Logistic Regression dell’esercizio precedente e un semplice Decision Tree. Puoi usare la scorciatoia get_model_results() per vedere subito il risultato del modello ensemble.
Questo esercizio fa parte del corso
Rilevamento delle frodi in Python
Istruzioni dell'esercizio
- Importa il pacchetto Voting Classifier.
- Definisci i tre modelli: usa la Logistic Regression di prima, la Random Forest degli esercizi precedenti e un Decision Tree con class weights bilanciati.
- Definisci il modello ensemble passando i tre classificatori con le rispettive etichette.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Import the package
from sklearn.ensemble import ____
# Define the three classifiers to use in the ensemble
clf1 = LogisticRegression(class_weight={0:1, 1:15}, random_state=5)
clf2 = ____(class_weight={0:1, 1:12}, criterion='gini', max_depth=8, max_features='log2',
min_samples_leaf=10, n_estimators=30, n_jobs=-1, random_state=5)
clf3 = DecisionTreeClassifier(random_state=5, class_weight="____")
# Combine the classifiers in the ensemble model
ensemble_model = ____(estimators=[('lr', ____), ('rf', ____), ('dt', ____)], voting='hard')
# Get the results
get_model_results(X_train, y_train, X_test, y_test, ensemble_model)