배깅

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의 배깅 분류기 (Breast-Cancer 데이터셋)

# 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

Ayo berlatih!

Python으로 배우는 트리 기반 Machine Learning

Preparing Video For Download...