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