TypeError: auc() 出现意外的关键字参数 ‘reorder’

huangapple go评论92阅读模式
英文:

TypeError: auc() got an unexpected keyword argument 'reorder'

问题

请告诉我为什么会出现这个错误?

def roc_aupr_score(y_true, y_score, average="macro"):
    def _binary_roc_aupr_score(y_true, y_score):
        precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
        return auc(recall, precision)

File "DDIMDL.py", line 387, in <module>
    main(args)
  File "DDIMDL.py", line 367, in main
    all_result, each_result = cross_validation(all_matrix, new_label, clf, event_num, seed, CV,
  File "DDIMDL.py", line 190, in cross_validation
    result_all, result_eve = evaluate(y_pred, y_score, y_true, event_num, set_name)
  File "DDIMDL.py", line 214, in evaluate
    result_all[1] = roc_aupr_score(y_one_hot, pred_score, average='micro')
  File "DDIMDL.py", line 301, in roc_aupr_score
    return _average_binary_score(_binary_roc_aupr_score, y_true, y_score, average)
  File "DDIMDL.py", line 298, in _average_binary_score
    score[c] = binary_metric(y_true_c, y_score_c)
  File "DDIMDL.py", line 281, in _binary_roc_aupr_score
    return auc(recall, precision)
TypeError: auc() got an unexpected keyword argument 'reorder'

我应该如何更正它?
请告诉我如何解决这个问题。

英文:

Kindly let me know why this error is coming?

def roc_aupr_score(y_true, y_score, average=&quot;macro&quot;):
    def _binary_roc_aupr_score(y_true, y_score):
        precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
        return auc(recall, precision, reorder=True)

File &quot;DDIMDL.py&quot;, line 387, in &lt;module&gt;
    main(args)
  File &quot;DDIMDL.py&quot;, line 367, in main
    all_result, each_result = cross_validation(all_matrix, new_label, clf, event_num, seed, CV,
  File &quot;DDIMDL.py&quot;, line 190, in cross_validation
    result_all, result_eve = evaluate(y_pred, y_score, y_true, event_num, set_name)
  File &quot;DDIMDL.py&quot;, line 214, in evaluate
    result_all[1] = roc_aupr_score(y_one_hot, pred_score, average=&#39;micro&#39;)
  File &quot;DDIMDL.py&quot;, line 301, in roc_aupr_score
    return _average_binary_score(_binary_roc_aupr_score, y_true, y_score, average)
  File &quot;DDIMDL.py&quot;, line 298, in _average_binary_score
    score[c] = binary_metric(y_true_c, y_score_c)
  File &quot;DDIMDL.py&quot;, line 281, in _binary_roc_aupr_score
    return auc(recall, precision, reorder=True)
TypeError: auc() got an unexpected keyword argument &#39;reorder&#39;

how can i correct it

kindly let me know how can solve the issue.

答案1

得分: 1

如评论中讨论的,reorder 参数已在版本 0.20 中弃用,并在 0.22 中移除。

def roc_aupr_score(y_true, y_score, average="macro"):
    def _binary_roc_aupr_score(y_true, y_score):
        precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
        return auc(recall, precision)

应该按预期工作如果不行你可以像这样对 `precision``recall` 进行排序

```python
precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
new_order = np.lexsort([recall, precision])
recall = recall[new_order]
precision = precision[new_order]
print(recall, precision)
return auc(recall, precision)
英文:

As discussed in the comments, reorder parameter has been deprecated in version 0.20 and removed in 0.22

def roc_aupr_score(y_true, y_score, average=&quot;macro&quot;):
    def _binary_roc_aupr_score(y_true, y_score):
        precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
        return auc(recall, precision)

Should work as intented. If not, you can sort precision and recall like this:

precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
new_order = np.lexsort([recall, precision])
recall = recall[new_order]
precision = precision[new_order]
print(recall , precision )
return auc(recall, precision)

huangapple
  • 本文由 发表于 2023年7月3日 14:30:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76602313.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定