We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
代码中coo_matrix返回的混淆矩阵axis=0的轴是指预测类别 错误的代码: precision = np.sum(cm_norm * (cm / cm.sum(axis=0))) recall = np.sum(cm_norm * (cm / np.expand_dims(cm.sum(axis=1), 1))) 正确的代码: recall = np.sum(cm_norm * (cm / cm.sum(axis=0))) precision= np.sum(cm_norm * (cm / np.expand_dims(cm.sum(axis=1), 1))) 但f1又恰好正确。 幸好论文里面没有打印这些数据。
下面是分析:我以BCubed的论文例子做实验 pred=np.array([0,0,0,0,1,1,1,2,2,2,2,2,2,2]) label=np.array([0,0,0,0,0,1,1,2,1,3,4,1,1,1]) cm= coo_matrix( (np.ones((14)), (pred, label)), shape=(3, 5), dtype=np.int),toarray() “”“ [[4, 0, 0, 0, 0], [1, 2, 0, 0, 0], [0, 4, 1, 1, 1]] ”“” np.expand_dims(cm.sum(axis=1), 1) ”“” [[4], [3], [7]] “”“ cm / np.expand_dims(cm.sum(axis=1),1) “”“ [[1. , 0. , 0. , 0. , 0. ], [0.33333333, 0.66666667, 0. , 0. , 0. ], [0. , 0.57142857, 0.14285714, 0.14285714, 0.14285714]] ”“” cm * cm / np.expand_dims(cm.sum(axis=1),1) """ [[4. , 0. , 0. , 0. , 0. ], [0.33333333, 1.33333333, 0. , 0. , 0. ], [0. , 2.28571429, 0.14285714, 0.14285714, 0.14285714]] """
np.sum(cm * cm / np.expand_dims(cm.sum(axis=1),1))/cm.sum()
这和你的代码是一样的算法,但是变量名错了: cm_norm = cm / cm.sum() recall = np.sum(cm_norm * (cm / np.expand_dims(cm.sum(axis=1), 1))) 这应该是精度 precision:(44/4+1/3+22/3+31/7+44/7)/14 = 0.5986394557823128 显然应该要除以每个预测类的总数 np.expand_dims(cm.sum(axis=1), 1) ”“” [[4], [3], [7]] “”“ axis=1才是计算精度的轴。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
代码中coo_matrix返回的混淆矩阵axis=0的轴是指预测类别
错误的代码:
precision = np.sum(cm_norm * (cm / cm.sum(axis=0)))
recall = np.sum(cm_norm * (cm / np.expand_dims(cm.sum(axis=1), 1)))
正确的代码:
recall = np.sum(cm_norm * (cm / cm.sum(axis=0)))
precision= np.sum(cm_norm * (cm / np.expand_dims(cm.sum(axis=1), 1)))
但f1又恰好正确。
幸好论文里面没有打印这些数据。
下面是分析:我以BCubed的论文例子做实验
pred=np.array([0,0,0,0,1,1,1,2,2,2,2,2,2,2])
label=np.array([0,0,0,0,0,1,1,2,1,3,4,1,1,1])
cm= coo_matrix(
(np.ones((14)), (pred, label)),
shape=(3, 5),
dtype=np.int),toarray()
“”“
[[4, 0, 0, 0, 0],
[1, 2, 0, 0, 0],
[0, 4, 1, 1, 1]]
”“”
np.expand_dims(cm.sum(axis=1), 1)
”“”
[[4],
[3],
[7]]
“”“
cm / np.expand_dims(cm.sum(axis=1),1)
“”“
[[1. , 0. , 0. , 0. , 0. ],
[0.33333333, 0.66666667, 0. , 0. , 0. ],
[0. , 0.57142857, 0.14285714, 0.14285714, 0.14285714]]
”“”
cm * cm / np.expand_dims(cm.sum(axis=1),1)
"""
[[4. , 0. , 0. , 0. , 0. ],
[0.33333333, 1.33333333, 0. , 0. , 0. ],
[0. , 2.28571429, 0.14285714, 0.14285714, 0.14285714]]
"""
np.sum(cm * cm / np.expand_dims(cm.sum(axis=1),1))/cm.sum()
0.5986394557823128
这和你的代码是一样的算法,但是变量名错了:
cm_norm = cm / cm.sum()
recall = np.sum(cm_norm * (cm / np.expand_dims(cm.sum(axis=1), 1)))
这应该是精度
precision:(44/4+1/3+22/3+31/7+44/7)/14 = 0.5986394557823128
显然应该要除以每个预测类的总数
np.expand_dims(cm.sum(axis=1), 1)
”“”
[[4],
[3],
[7]]
“”“
axis=1才是计算精度的轴。
The text was updated successfully, but these errors were encountered: