-
카테고리
-
세부 분야
딥러닝 · 머신러닝
-
해결 여부
미해결
마지막에 AUC 까지 넣은 함수를 어떻게 실행하는지 모르겠습니다.
21.10.08 13:47 작성 조회수 105
0
def get_eval_by_threshold(y_test , pred_proba_c1, thresholds):
for custom_threshold in thresholds:
binarizer = Binarizer(threshold=custom_threshold).fit(pred_proba_c1)
custom_predict = binarizer.transform(pred_proba_c1)
print('임곗값:',custom_threshold)
get_clf_eval(y_test , custom_predict)
print()
get_eval_by_threshold(y_test, pred_proba[:,1].reshape(-1,1), thresholds)
밑에 이거 코드를 추가하고 실행하는 것이 아닌가요?
답변을 작성해보세요.
0
권 철민
지식공유자2021.10.08
안녕하십니까,
음, 질문을 정확히 이해하지 못했습니다만,
피마 인디언 당뇨병 예측에서 def get_eval_by_threshold(y_test , pred_proba_c1, thresholds) 함수 사용을 물어보신 건가요?
실습 예제 피마 인디언 당뇨병 예측.ipynb를 보시면 get_clf_eval() 함수가 아래와 같이 되어 있습니다.
def get_clf_eval(y_test, pred=None, pred_proba=None):
confusion = confusion_matrix( y_test, pred)
accuracy = accuracy_score(y_test , pred)
precision = precision_score(y_test , pred)
recall = recall_score(y_test , pred)
f1 = f1_score(y_test,pred)
# ROC-AUC 추가
roc_auc = roc_auc_score(y_test, pred_proba)
print('오차 행렬')
print(confusion)
# ROC-AUC print 추가
print('정확도: {0:.4f}, 정밀도: {1:.4f}, 재현율: {2:.4f},\
F1: {3:.4f}, AUC:{4:.4f}'.format(accuracy, precision, recall, f1, roc_auc))
적어주신 get_clf_eval(y_test , custom_predict) 는 잘못되어 있습니다.
실습 예제의 get_eval_by_threshold()에서 get_clf_eval()함수의 인자는 세개 입니다.
get_clf_eval(y_test , custom_predict, pred_proba_c1) 입니다.
def get_eval_by_threshold(y_test , pred_proba_c1, thresholds):
# thresholds 리스트 객체내의 값을 차례로 iteration하면서 Evaluation 수행.
for custom_threshold in thresholds:
binarizer = Binarizer(threshold=custom_threshold).fit(pred_proba_c1)
custom_predict = binarizer.transform(pred_proba_c1)
print('임곗값:',custom_threshold)
# roc_auc_score 관련 수정
get_clf_eval(y_test , custom_predict, pred_proba_c1)
그래서 호출은 get_eval_by_threshold(y_test, pred_proba[:,1].reshape(-1,1), thresholds ) 로 하시면 됩니다.
감사합니다.
답변 1