Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中使用二进制向量计算预测_Python_Numpy - Fatal编程技术网

在python中使用二进制向量计算预测

在python中使用二进制向量计算预测,python,numpy,Python,Numpy,我想使用两个向量(预测,实际)并用Python对预测进行简单评估:(两个向量都是Ndarray) 我尝试了&&操作符和numpy.mul。。。总有一些转变要做。我希望你能做一些非常简单的事情。sum([prediction[I]==actual[I]for I in range(len(prediction)))/len(prediction)sum([prediction[I]==actual[I]for I in range(len(prediction)))/len(prediction)

我想使用两个向量(预测,实际)并用Python对预测进行简单评估:(两个向量都是Ndarray)

我尝试了
&&
操作符和
numpy.mul
。。。总有一些转变要做。我希望你能做一些非常简单的事情。

sum([prediction[I]==actual[I]for I in range(len(prediction)))/len(prediction)
sum([prediction[I]==actual[I]for I in range(len(prediction)))/len(prediction)

输出:

50.0
输出:

50.0

您还可以使用标准python运算符实现这一点:

>>> prediction = [ 1, 1, 1, 0, 0, 1 ];
>>> actual     = [ 1, 0, 1, 0, 1, 0 ];
>>> 100.0 * sum([not p ^ a for p, a in zip(prediction, actual)])/len(prediction)

您还可以使用标准python运算符实现这一点:

>>> prediction = [ 1, 1, 1, 0, 0, 1 ];
>>> actual     = [ 1, 0, 1, 0, 1, 0 ];
>>> 100.0 * sum([not p ^ a for p, a in zip(prediction, actual)])/len(prediction)
predicted=[1,0,1,1,0,0,1]
实际值=[1,1,0,1,0,0,0]
断言len(预测)=len(实际)
分数=总和(映射(λx:1。如果x[0]==x[1],否则为0.,压缩(预测,实际))/len(预测)
打印(分数)#其中0表示完全不匹配,1表示完全匹配
predicted=[1,0,1,1,0,0,1]
实际值=[1,1,0,1,0,0,0]
断言len(预测)=len(实际)
分数=总和(映射(λx:1。如果x[0]==x[1],否则为0.,压缩(预测,实际))/len(预测)
打印(分数)#其中0表示完全不匹配,1表示完全匹配

当预测和实际值为0时,
预测*实际值
将为0,而不是1。当预测和实际值为0时,
预测*实际值
将为0,而不是1。
>>> prediction = [ 1, 1, 1, 0, 0, 1 ];
>>> actual     = [ 1, 0, 1, 0, 1, 0 ];
>>> 100.0 * sum([not p ^ a for p, a in zip(prediction, actual)])/len(prediction)
predicted = [1, 0, 1, 1, 0, 0, 1]
actual    = [1, 1, 0, 1, 0, 0, 0]
assert len(predicted) == len(actual)
score = sum(map(lambda x: 1. if x[0] == x[1] else 0., zip(predicted, actual))) / len(predicted)
print(score) # <0,1> where 0=complete mismatch and 1=complete match