Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

python - ValueError: unknown format is not supported : ROC Curve

I have just updated python version from 3.5 to 3.7 and getting an error in constructing ROC curve. I did not change anything in code but it gives some unknown error

Code

# ROC Curve

from sklearn.metrics import confusion_matrix, accuracy_score, roc_auc_score, roc_curve
y_pred_proba = predictions[::, 1]
print("y_pred_proba", y_pred_proba)
print("y_test", y_test)

fpr, tpr, _ = roc_curve(y_test, y_pred_proba)
auc = roc_auc_score(y_test, y_pred_proba)

plt.figure(figsize=(7, 3))

Values

y_pred_proba [0.1746994 0.22792926 0.60020134 0.60857445 0.38630289 0.16318228 0.20503542 0.76781874 0.89951127 0.13657112 0.36836385 0.23833946 0.43924601 0.9874083 0.98404103 0.1003149 0.94596688 0.36480605 0.48716601 0.04158647 0.8624937 0.93881636 0.54065999 0.38538261 0.48002784 0.9874083 0.76781874 0.95791353 0.48002784 0.2448756 0.98404103 0.06473023 0.34080482 0.11897602 0.07883822 0.08000581 0.38630289 0.2546955 0.95515939 0.47123327 0.93544655 0.52027235 0.23231433 0.45185196 0.78456432 0.92415415 0.22408711 0.82322069 0.12670252 0.50150037 0.2546955 0.93881636 0.33043862 0.52027235 0.07964735 0.11961717 0.79551265 0.0378607 0.34080482 0.87411928 0.85397911 0.9874083 0.18885285 0.93140091 0.87411928 0.52027235 0.48716601 0.19411124 0.06473023 0.79551265 0.76781874 0.81180605 0.06833817 0.45406719 0.54006639 0.48002784 0.12468554 0.38630289 0.18068918 0.9874083 0.79551265 0.43924601 0.86979492 0.15120609 0.56046085 0.27958234 0.50261158 0.23231433 0.42496329 0.98404103 0.93881636 0.96244002 0.38049589 0.9874083 0.38354959 0.8624937 0.48716601 0.89951127 0.98404103 0.37245044 0.38630289 0.49835809 0.9874083 0.27773467 0.98404103 0.40968608 0.3587635 0.1003149 0.2572435 0.52492011 0.19933781 0.38538261 0.24401876 0.06473023 0.82322069]

y_test [1 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 1 0 0 0 1 1 1 0 1 1 1 0 0 0 1 0 0 0 0 1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0 0 0 0 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 0 0 0 1 1 1 1 1 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 01]

Traceback (most recent call last):
  File "/home/khawar/deepface/tests/Ensemble-Face-Recognition.py", line 897, in <module>
    fpr, tpr, _ = roc_curve(y_test, y_pred_proba)
  File "/home/khawar/.local/lib/python3.6/site-packages/sklearn/utils/validation.py", line 72, in inner_f
    return f(**kwargs)
  File "/home/khawar/.local/lib/python3.6/site-packages/sklearn/metrics/_ranking.py", line 776, in roc_curve
    y_true, y_score, pos_label=pos_label, sample_weight=sample_weight)
  File "/home/khawar/.local/lib/python3.6/site-packages/sklearn/metrics/_ranking.py", line 539, in _binary_clf_curve
    raise ValueError("{0} format is not supported".format(y_type))
ValueError: unknown format is not supported

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

if we print the value of type_of_target(y_test) the output value is "unknown". Now, we have to change the unknown to integer. So we will do like this

y_test = y_test.astype(int)

Overall Code

from sklearn.metrics import confusion_matrix, accuracy_score, roc_auc_score, roc_curve

y_pred_proba = predictions[::, 1]
y_test = y_test.astype(int)


fpr, tpr, _ = roc_curve(y_test, y_pred_proba)
auc = roc_auc_score(y_test, y_pred_proba)

plt.figure(figsize=(7, 3))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...