我想计算每个混淆矩阵的FPR和TPR,但我收到此错误
def true_false_positive(matrix):
tpr=[]
fpr=[]
for i in range(matrix.shape[0]):
tpr[i]= matrix[i,0,0]/(matrix[i,0,0]+matrix[i,0,1])
fpr[i]= matrix[i,1,1]/(matrix[i,1,0]+matrix[i,1,1])
return tpr, fpr
当我初始化TPR和FPR为dic时,它工作了,但我希望它们作为数组,因为我稍后会做更多的计算当我执行true_false_positive (matrix1)我收到
5 for i in range(matrix.shape[0]):
----> 6 tpr[i].append(matrix[i,0,0]/(matrix[i,0,0]+matrix[i,0,1]))
7 fpr[i]= matrix[i,1,1]/(matrix[i,1,0]+matrix[i,1,1])
8
IndexError: list index out of range
谢谢你,我改了它,它工作了
def true_false_positive(matrix):
tpr=[]
fpr=[]
for i in range(matrix.shape[0]):
tpr.append(matrix[i,0,0]/(matrix[i,0,0]+matrix[i,0,1]))
fpr.append(matrix[i,1,1]/(matrix[i,1,0]+matrix[i,1,1]))
return tpr, fpr