混淆矩阵(confusion matrix)

本文介绍了混淆矩阵的概念,包括真阳性(TP)、真阴性(TN)、假阳性(FP)和假阴性(FN),并展示了如何使用`sklearn`库实现混淆矩阵,以及显示混淆矩阵的matshow方法。此外,文章讨论了预测错误率、预测正确率、召回率、假正率、精确率和F1-score等关键评价指标的计算,并指出在`sklearn`中如何定制positive类。最后,文章探讨了Receiver Operating Characteristic (ROC)曲线和ROC AUC,强调好的模型应具备高TPR和低FPR,以在ROC曲线的左上方。
摘要由CSDN通过智能技术生成

git源码地址 https://github.com/xuman-Amy/Model-evaluation-and-Hypamameter-tuning

数据地址 https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+(Diagnostic)

True positive (TP) :真实为P,预测为P

True negative (TN): 真实为N,预测为N

False positive (FP):真实为N,预测为P

False negative (FN):真实为P,预测为N

【sklearn 实现confusion matrix】

from sklearn .metrics import confusion_matrix
pipe_lr.fit(X_train, y_train)
y_pred = pipe_lr.predict(X_test)
conmat = confusion_matrix(y_true = y_test, y_pred = y_pred)
print(conmat)

用matshow显示出

# plot confusion matrix
fig, ax = plt.subplots(figsize = (2.5, 2.5))
ax.matshow(confmat, cmap = plt.cm.Blues, alpha = 0.3)
for i in range(confmat.shape[0]):
    for j in range(confmat.shape[1]):
        ax.text(x = j, y = i,          #ax.text()在轴上添加文本
                s 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值