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

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

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

问题

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

  1. def roc_aupr_score(y_true, y_score, average="macro"):
  2. def _binary_roc_aupr_score(y_true, y_score):
  3. precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
  4. return auc(recall, precision)
  1. File "DDIMDL.py", line 387, in <module>
  2. main(args)
  3. File "DDIMDL.py", line 367, in main
  4. all_result, each_result = cross_validation(all_matrix, new_label, clf, event_num, seed, CV,
  5. File "DDIMDL.py", line 190, in cross_validation
  6. result_all, result_eve = evaluate(y_pred, y_score, y_true, event_num, set_name)
  7. File "DDIMDL.py", line 214, in evaluate
  8. result_all[1] = roc_aupr_score(y_one_hot, pred_score, average='micro')
  9. File "DDIMDL.py", line 301, in roc_aupr_score
  10. return _average_binary_score(_binary_roc_aupr_score, y_true, y_score, average)
  11. File "DDIMDL.py", line 298, in _average_binary_score
  12. score[c] = binary_metric(y_true_c, y_score_c)
  13. File "DDIMDL.py", line 281, in _binary_roc_aupr_score
  14. return auc(recall, precision)
  15. TypeError: auc() got an unexpected keyword argument 'reorder'

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

英文:

Kindly let me know why this error is coming?

  1. def roc_aupr_score(y_true, y_score, average=&quot;macro&quot;):
  2. def _binary_roc_aupr_score(y_true, y_score):
  3. precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
  4. return auc(recall, precision, reorder=True)
  1. File &quot;DDIMDL.py&quot;, line 387, in &lt;module&gt;
  2. main(args)
  3. File &quot;DDIMDL.py&quot;, line 367, in main
  4. all_result, each_result = cross_validation(all_matrix, new_label, clf, event_num, seed, CV,
  5. File &quot;DDIMDL.py&quot;, line 190, in cross_validation
  6. result_all, result_eve = evaluate(y_pred, y_score, y_true, event_num, set_name)
  7. File &quot;DDIMDL.py&quot;, line 214, in evaluate
  8. result_all[1] = roc_aupr_score(y_one_hot, pred_score, average=&#39;micro&#39;)
  9. File &quot;DDIMDL.py&quot;, line 301, in roc_aupr_score
  10. return _average_binary_score(_binary_roc_aupr_score, y_true, y_score, average)
  11. File &quot;DDIMDL.py&quot;, line 298, in _average_binary_score
  12. score[c] = binary_metric(y_true_c, y_score_c)
  13. File &quot;DDIMDL.py&quot;, line 281, in _binary_roc_aupr_score
  14. return auc(recall, precision, reorder=True)
  15. 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 中移除。

  1. def roc_aupr_score(y_true, y_score, average="macro"):
  2. def _binary_roc_aupr_score(y_true, y_score):
  3. precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
  4. return auc(recall, precision)
  5. 应该按预期工作如果不行你可以像这样对 `precision` `recall` 进行排序
  6. ```python
  7. precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
  8. new_order = np.lexsort([recall, precision])
  9. recall = recall[new_order]
  10. precision = precision[new_order]
  11. print(recall, precision)
  12. return auc(recall, precision)
英文:

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

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

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

  1. precision, recall, pr_thresholds = precision_recall_curve(y_true, y_score)
  2. new_order = np.lexsort([recall, precision])
  3. recall = recall[new_order]
  4. precision = precision[new_order]
  5. print(recall , precision )
  6. 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:

确定