【问题标题】:ValueError: unknown format is not supported : ROC CurveValueError:不支持未知格式:ROC 曲线
【发布时间】:2021-04-07 15:02:59
【问题描述】:

我刚刚将 python 版本从 3.5 更新到 3.7,并在构建 ROC 曲线时出错。我没有更改代码中的任何内容,但它给出了一些未知错误

代码

# 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))

价值观

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

【问题讨论】:

  • 更新python后你使用的是同一个sklearn版本吗?
  • 对不起,我不记得我使用的是相同版本还是不同版本

标签: python python-3.x pandas numpy scikit-learn


【解决方案1】:

如果我们打印type_of_target(y_test) 的值,则输出值为“未知”。现在,我们必须将未知数更改为整数。所以我们会这样做

y_test = y_test.astype(int)

总体代码

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))

【讨论】:

    猜你喜欢
    • 2020-02-14
    • 2017-11-12
    • 2019-10-01
    • 2017-10-19
    • 1970-01-01
    • 2012-09-17
    • 2018-01-03
    • 2019-12-26
    • 2019-02-27
    相关资源
    最近更新 更多