결정 트리로 특성 중요도 계산하기
심장 질환 데이터셋을 사용해 심장 질환 위험 환자를 식별하는 결정 트리 분류기를 만들었어요. 이제 모델을 설명하기 위해 특성 중요도를 분석해 심장 질환 예측의 핵심 요인을 파악하고, 보다 정밀한 의료 개입이 가능하도록 해야 해요.
matplotlib.pyplot은 plt로 임포트되어 있어요. X_train과 y_train은 미리 로드되어 있어요.
이 연습은 강의의 일부입니다
Python으로 배우는 Explainable AI
연습 안내
model에서 특성 중요도를 추출하세요.- 주어진
feature_names에 대해feature_importances를 그래프로 표시하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
model = DecisionTreeClassifier(random_state=42)
model.fit(X_train, y_train)
# Derive feature importances
feature_importances = ____
feature_names = X_train.columns
# Plot the feature importances
____
plt.show()