python基础代码的含义_python里面一些简单代码的含义是什么?(题主零基础)

我想绘制一个混淆矩阵的图片,类似于这种效果的:我在网上找到了代码,但是读不懂,具体不知道怎么操作。我现在数据都有,计算好的矩阵也有,原数据的分类情况什么的都有,可就是不知...

我想绘制一个混淆矩阵的图片,类似于这种效果的:

我在网上找到了代码,但是读不懂,具体不知道怎么操作。我现在数据都有,计算好的矩阵也有,原数据的分类情况什么的都有,可就是不知道怎么用Python操作,请熟悉Python的高手帮我解答一下,十分感谢!

代码如下:

from sklearn.metrics import confusion_matriximport matplotlib.pyplot as pltimport numpy as np#load labels.labels = []file = open('labels.txt', 'r')lines = file.readlines()for line in lines: labels.append(line.strip())file.close()

y_true = []y_pred = []#load true and predict labels.file = open('predict.txt', 'r')lines = file.readlines()for line in lines: y_true.append(int(line.split(" ")[1].strip())) y_pred.append(int(line.split(" ")[0].strip()))file.close()tick_marks = np.array(range(len(labels))) + 0.5def plot_confusion_matrix(cm, title='Confusion Matrix', cmap = plt.cm.binary): plt.imshow(cm, interpolation='nearest', cmap=cmap) plt.title(title) plt.colorbar() xlocations = np.array(range(len(labels))) plt.xticks(xlocations, labels, rotation=90) plt.yticks(xlocations, labels) plt.ylabel('True label') plt.xlabel('Predicted label')cm = confusion_matrix(y_true, y_pred)np.set_printoptions(precision=2)cm_normalized = cm.astype('float')/cm.sum(axis=0)[:, np.newaxis]

(字数限制,剩下的部分贴在追问里了。)

英文方面我懂,简单的语句,符号啥的,也懂一些。但是就是不知道具体怎么操作,要把数据贴到代码的某些位置呢,还是贴到txt文件里,然后直接让Python调用呢,调用的画,路径怎么写,写在哪儿?等等操作的问题。

plt.figure(figsize=(12,8), dpi=120)

#set the fontsize of label.

#for label in plt.gca().xaxis.get_ticklabels():

# label.set_fontsize(8)

#text portion

()

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值