ROC_AUC百分比计算给NAN

发布于 2025-01-26 05:10:54 字数 413 浏览 4 评论 0原文

我正在尝试计算数据的ROC分数,但导致NAN。

代码:

scoring = 'roc_auc'
kfold= KFold(n_splits=10, random_state=42, shuffle=True)
model = LinearDiscriminantAnalysis()
results = cross_val_score(model, df_n, y, cv=kfold, scoring=scoring)
print("AUC: %.3f (%.3f)" % (results.mean(), results.std()))

df_n是来自归一化值的数组,我还尝试使用数据集的x数据值尝试。 Y是二进制值的数组。

DF_N形状:( 150,4) Y形:(150,)

我很难过,应该有效!

I am trying to calculate the ROC score for my data but it is resulting in nan.

The code:

scoring = 'roc_auc'
kfold= KFold(n_splits=10, random_state=42, shuffle=True)
model = LinearDiscriminantAnalysis()
results = cross_val_score(model, df_n, y, cv=kfold, scoring=scoring)
print("AUC: %.3f (%.3f)" % (results.mean(), results.std()))

df_n is an array from the normalised values, I also tried it just with the X data value from the dataset.
y is an array of binary values.

df_n shape: (150, 4)
y shape: (150,)

I am stumped, it should work!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只为守护你 2025-02-02 05:10:54

问题在于roc_auc_score期望在多类分类的情况下,而不是预测。但是,使用该代码,得分将获得预测的输出。

使用新得分手:

from sklearn.metrics import roc_auc_score, make_scorer

multi_roc_scorer = make_scorer(lambda y_in, y_p_in: roc_auc_score(y_in, y_p_in, multi_class='ovr'), needs_proba=True)
scores = cross_validate(model, X_s, y_s, scoring=multi_roc_scorer, cv=cv, error_score="raise")

The problem is that roc_auc_score expects the probabilities and not the predictions in the case of multi-class classification. However, with that code the score is getting the output of predict instead.

Use a new scorer:

from sklearn.metrics import roc_auc_score, make_scorer

multi_roc_scorer = make_scorer(lambda y_in, y_p_in: roc_auc_score(y_in, y_p_in, multi_class='ovr'), needs_proba=True)
scores = cross_validate(model, X_s, y_s, scoring=multi_roc_scorer, cv=cv, error_score="raise")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文