使用python中的二进制向量评估预测

the*_*ech 1 python numpy

我想采用两个向量(预测,实际)并对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% 
Run Code Online (Sandbox Code Playgroud)

我尝试过&&操作员numpy.mul......总会有一些转变要做.我很欣赏一些非常简单的事情.

fal*_*tru 7

>>> 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
Run Code Online (Sandbox Code Playgroud)