网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

学习roc_curve函数,能精准掌握模型评估利器?

GG网络技术分享 2025-11-13 03:37 1


python from sklearn.metrics import roccurve, auc from sklearn.datasets import makeclassification from sklearn.modelselection import traintestsplit from sklearn.linearmodel import LogisticRegression import matplotlib.pyplot as plt

X, y = makeclassification Xtrain, Xtest, ytrain, ytest = traintest_split

model = LogisticRegression model.fit

ypredproba = model.predict_proba # 取概率值

fpr, tpr, thresholds = roc_curve

roc_auc = auc

plt.figure plt.plot' % roc_auc) plt.plot plt.xlim plt.ylim plt.xlabel plt.ylabel plt.title plt.legend plt.show

在这段代码中, 我们先说说生成了一个具有1000个样本和20个特征的分类数据集,并将其分为训练集和测试集。然后我们训练了一个逻辑回归模型,并用该模型在测试集上进行预测,以得到预测概率。接着,我们用roc_curve函数计算FPR、TPR和阈值,并用auc函数计算AUC。再说说我们用matplotlib绘制了ROC曲线,并kan得出来了曲线下的面积。

标签:

提交需求或反馈

Demand feedback