Voting Classifier
ここでは、以前のRandom Forestによる不正検知モデルを強化するために、3つのMachine Learningモデルを1つに統合します。前の演習で作成したLogistic Regression、これまで使ってきたRandom Forest、そしてシンプルなDecision Treeを組み合わせます。アンサンブルモデルの即時の結果を見るには、ショートカットの get_model_results() を使えます。
この演習はコースの一部です
Pythonで学ぶ不正検知
演習の手順
- Voting Classifier のパッケージをインポートします。
- 3つのモデルを定義します。以前のLogistic Regression、これまでのRandom Forest、そしてクラス重みをバランスさせたDecision Treeを使います。
- それぞれのラベルを付けた3つの分類器を入力して、アンサンブルモデルを定義します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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)