我有一个创建混淆矩阵的函数
def disp_conf_mat(y_act, y_pred, conf_mat_name):
data = {'y_Actual': y_act,
'y_Predicted': y_pred
}
df = pd.DataFrame(data, columns=['y_Actual','y_Predicted'])
confusion_matrix = pd.crosstab(df['y_Actual'], df['y_Predicted'], rownames=['Actual'], colnames=['Predicted'])
sn.heatmap(confusion_matrix, annot=True)
plt.savefig(conf_mat_name)
plt.close()
但如果实际值为[0,1,2,3],预测值均为零[0,0,0,0],则混淆矩阵将不是正方形4x4,而只是4x1
Predicted 0
Actual
0 1
1 1
2 1
3 1
我如何填充没有得到任何预测值的其他列?(例如,此处第1、2和3列)
如果需要所有可能的值,则应添加^{} :
相关问题 更多 >
编程相关推荐