from sklearn.metrics import accuracy_score,precision_score,recall_score,confusion_matrix
#오차행렬, 정확도 , 정밀도 , 재현율을 출력해주는 함수 생성 
def get_clf_eval(y_test , pred):
    #오차행렬
    confusion = confusion_matrix(y_test, pred)
    #정확도
    accuracy = accuracy_score(y_test , pred)
    #정밀도
    precision = precision_score(y_test , pred)
    #재현율
    recall = recall_score(y_test , pred)
    print('오차 행렬',confusion)
    print('정확도: {0:.4f}, 정밀도: {1:.4f}, 재현율: {2:.4f}'.format(accuracy , precision ,recall))
'''정밀도 & 재현율'''
#생성한 함수 사용 의사결정 나무 학습 후 결과 확인해보기
--> 위에 titanic_dtclf를 가져와서 사용 
from sklearn.metrics import classification_report
print(classification_report(y, titanic_dtclf.predict(X)))
-->  classification_report를 사용하면 편리하게 확인이 가능하다. 
print(get_clf_eval(y, titanic_dtclf.predict(X)))
'Python' 카테고리의 다른 글
| Python - 랜덤포레스트 iris (0) | 2022.10.19 | 
|---|---|
| Python - 머신러닝 모델 평가 [최종] (1) | 2022.10.17 | 
| Python - 모델 평가 오차행렬 (2) | 2022.10.17 | 
| Python - 교차 검증 정리 (1) | 2022.10.17 | 
| Python - Hyperopt 교차검증 (0) | 2022.10.17 | 



