我想用两个向量(预测的,实际的)对 Python 中的预测进行简单的评估:(两个向量都是 ndarrays)
prediction = [ 1 1 1 0 0 1 ]
actual = [ 1 0 1 0 1 0 ]
score = 1 + 0 + 1 + 1 + 0 + 0 / 6 = 3/6 = 50%
我尝试了 && 运算符和 numpy.mul ...总有一些转换要做。我会很感激一些非常简单的东西。
请您参考如下方法:
>>> import numpy as np
>>> prediction = np.array([1,1,1,0,0,1])
>>> actual = np.array([1,0,1,0,1,0])
>>> np.sum(prediction == actual, dtype=float) / len(prediction)
0.5
>>> np.mean(prediction == actual)
0.5
