バギング

Pythonで学ぶ木ベースのMachine Learning

Elie Kawerk

Data Scientist

アンサンブル学習

【投票分類器】

  • 同一の訓練データ、
  • 異なるアルゴリズム。

【バギング】

  • 同一アルゴリズム、
  • 訓練データの異なるサブセット。
Pythonで学ぶ木ベースのMachine Learning

バギング

  • バギング=ブートストラップ集約。

  • ブートストラップ手法を用いる。

  • アンサンブル内の各モデルの分散を低減。

Pythonで学ぶ木ベースのMachine Learning

ブートストラップ

ブートストラップ

Pythonで学ぶ木ベースのMachine Learning

バギング:学習

学習-バギング

Pythonで学ぶ木ベースのMachine Learning

バギング:予測

予測-バギング

Pythonで学ぶ木ベースのMachine Learning

バギング:分類と回帰

【分類】

  • 予測を多数決で集約。
  • scikit-learn の BaggingClassifier

【回帰】

  • 予測を平均で集約。
  • scikit-learn の BaggingRegressor
Pythonで学ぶ木ベースのMachine Learning

sklearn のバギング分類器(乳がんデータ)

# Import models and utility functions
from sklearn.ensemble import BaggingClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split

# Set seed for reproducibility
SEED = 1

# Split data into 70% train and 30% test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
                                                    stratify=y,
                                                    random_state=SEED)
Pythonで学ぶ木ベースのMachine Learning
# Instantiate a classification-tree 'dt'
dt = DecisionTreeClassifier(max_depth=4, min_samples_leaf=0.16, random_state=SEED)

# Instantiate a BaggingClassifier 'bc' bc = BaggingClassifier(base_estimator=dt, n_estimators=300, n_jobs=-1)
# Fit 'bc' to the training set bc.fit(X_train, y_train) # Predict test set labels y_pred = bc.predict(X_test) # Evaluate and print test-set accuracy accuracy = accuracy_score(y_test, y_pred) print('Accuracy of Bagging Classifier: {:.3f}'.format(accuracy))
Accuracy of Bagging Classifier: 0.936
Pythonで学ぶ木ベースのMachine Learning

演習に進みましょう!

Pythonで学ぶ木ベースのMachine Learning

Preparing Video For Download...