시작하기무료로 시작하기

Voting Classifier

이번에는 이전에 만든 Random Forest 사기 탐지 모델을 개선하기 위해, 세 가지 Machine Learning 모델을 하나로 합쳐 보겠습니다. 이전 연습 문제에서 사용한 Logistic Regression, 우리에게 익숙한 Random Forest 모델, 그리고 간단한 Decision Tree를 결합할 거예요. 앙상블 모델의 즉시 결과를 확인하려면 get_model_results() 지름길 함수를 사용하세요.

이 연습은 강의의 일부입니다

Python으로 배우는 사기 탐지

강의 보기

연습 안내

  • Voting Classifier 패키지를 임포트하세요.
  • 세 개의 모델을 정의하세요. 이전의 Logistic Regression, 앞선 연습 문제의 Random Forest, 그리고 클래스 가중치를 균형화한 Decision Tree를 사용합니다.
  • 세 분류기와 각자의 레이블을 입력하여 앙상블 모델을 정의하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# 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)
코드 편집 및 실행