투표

Python에서의 앙상블 기법

Román de las Heras

Data Scientist, Appodeal

관객에게 묻기

관객에게 묻기.gif

대중의 지혜

  • 집단 지성
  • 큰 집단의 판단 >= 단일 전문가
  • 문제 해결
  • 의사 결정
  • 혁신
  • 예측
Python에서의 앙상블 기법

다수결 투표

속성

  • 분류 문제
  • 다수결: 최빈값
  • 분류기 수 홀수(3+)

다중 모드 예측.png

현명한 집단의 조건

  • 다양성: 서로 다른 알고리즘·데이터셋
  • 독립적이고 비상관
  • 개별 지식 활용
  • 개별 예측 집계
Python에서의 앙상블 기법

scikit-learn으로 투표 앙상블

from sklearn.ensemble import VotingClassifier

clf_voting = VotingClassifier( estimators=[ ('label1', clf_1), ('label2', clf_2), ('labelN', clf_N)])

성능 평가

# Get the accuracy score 
acc = accuracy_score(y_test, y_pred)
print("Accuracy: {:0.3f}".format(acc))
Accuracy: 0.938
# Create the individual models
clf_knn = KNeighborsClassifier(5)
clf_dt = DecisionTreeClassifier()
clf_lr = LogisticRegression()

# Create voting classifier clf_voting = VotingClassifier( estimators=[ ('knn', clf_knn), ('dt', clf_dt), ('lr', clf_lr)])
# Fit it to the training set and predict clf_voting.fit(X_train, y_train) y_pred = clf_voting.predict(X_test)
Python에서의 앙상블 기법

한번 해 보겠습니다!

Python에서의 앙상블 기법

Preparing Video For Download...