python-3.x - 交叉验证时如何获取AUC-ROC而不是准确率?

标签 python-3.x machine-learning scikit-learn

我正在对数据集进行分类,并使用交叉验证进行建模。交叉验证给出了每次折叠的准确性,因为类别不平衡,准确性不是正确的衡量标准。我想要获得 AUC-ROC 而不是准确性。

最佳答案

cross_val_score 支持大量评分选项。

提到了详尽的列表 here .

['accuracy', 'recall_samples', 'f1_macro', 'adjusted_rand_score', 'recall_weighted', 'precision_weighted', 'recall_macro', 'homogeneity_score', 'neg_mean_squared_log_error', 'recall_micro', 'f1', 'neg_log_loss', 'roc_auc', 'average_precision', 'f1_weighted', 'r2', 'precision_macro', 'explained_variance', 'v_measure_score', 'neg_mean_absolute_error', 'completeness_score', 'fowlkes_mallows_score', 'f1_micro', 'precision_samples', 'mutual_info_score', 'neg_mean_squared_error', 'balanced_accuracy', 'neg_median_absolute_error', 'precision_micro', 'normalized_mutual_info_score', 'adjusted_mutual_info_score', 'precision', 'f1_samples', 'brier_score_loss', 'recall']

这是一个展示如何使用 auc_roc 的示例。

>>> from sklearn import datasets, linear_model
>>> from sklearn.model_selection import cross_val_score
>>> import numpy as np
>>> X, y = datasets.load_breast_cancer(return_X_y=True)
>>> model = linear_model.SGDClassifier(max_iter=50, random_state=7)
>>> print(cross_val_score(model, X, y, cv=5, scoring = 'roc_auc'))  

[0.96382429 0.96996124 0.95573441 0.96646546 0.91113347]

关于python-3.x - 交叉验证时如何获取AUC-ROC而不是准确率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55769836/

相关文章:

python - PIL/Pillow 2.8.1 和 3.1.1 Image.rotate 的区别

python - ttk.Spinbox 和 tk.Spinbox 之间的行为差​​异是什么(ttk 中的箭头方向有问题吗?)

python - 你如何制作一个接受命令的控制台应用程序?

python - 从分类器中检索训练功能名称列表

python - 我如何将 txt 文件解析为 Python 中的列表

math - 梯度下降算法中的delta到底是什么意思?

python - TensorFlow One 热编码器?

machine-learning - 与子类别的区分

python - 使用 scikit-learn 的 Web 应用程序

machine-learning - 特征重要性 - Bagging、scikit-learn