인프런 커뮤니티 질문&답변

jnood님의 프로필 이미지

작성한 질문수

[퇴근후딴짓] 빅데이터 분석기사 실기 (작업형1,2,3)

작업형2 모의문제1

섹션 6 작업형 2 정확도 오류 원인 질문드립니다! Classification metrics can't handle a mix of binary and continuous targets

해결된 질문

23.06.19 16:04 작성

·

1.2K

0

from sklearn.model_selection import train_test_split

X_tr,X_val,y_tr,y_val=train_test_split(train.drop('Attrition_Flag',axis=1),train['Attrition_Flag'],test_size=0.2,random_state=2023)

from sklearn.ensemble import RandomForestClassifier

rf=RandomForestClassifier(random_state=2023)
rf.fit(X_tr,y_tr)
pred=rf.predict_proba(X_val)

from sklearn.metrics import accuracy_score

# 정확도
print(accuracy_score(y_val, pred[:,1]))

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-63-aa6b6ce781f8> in <cell line: 10>()
      8 
      9 # 정확도
---> 10 print(accuracy_score(y_val, pred[:,1]))

2 frames
/usr/local/lib/python3.10/dist-packages/sklearn/metrics/_classification.py in _check_targets(y_true, y_pred)
     93 
     94     if len(y_type) > 1:
---> 95         raise ValueError(
     96             "Classification metrics can't handle a mix of {0} and {1} targets".format(
     97                 type_true, type_pred

ValueError: Classification metrics can't handle a mix of binary and continuous targets

혹은

print(accuracy_score(y_val, pred)) 실행 시, 
오류2번 Classification metrics can't handle a mix of binary and continuous-multioutput targets

해당 코드로 제출까지는 잘 되고 있습니다.

그러나 정확도 측정 시 오류가 발생하여, 제출에 문제가 있는 것인가 불안하여 오류 현상 문의드립니다..!

답변 1

0

퇴근후딴짓님의 프로필 이미지
퇴근후딴짓
지식공유자

2023. 06. 19. 16:36

정확도를 예측할 때는 predict 예측값으로 확인해야 합니다.

roc_auc만 predict_proba로 예측합니다.

jnood님의 프로필 이미지

작성한 질문수

질문하기