種解決方案是使用簡單的統(tǒng)計解釋,其中我們將使用0.5截止值。因此,高于0.5的所有內(nèi)容將被視為1,低于0的內(nèi)容將被視為0
import numpy as np
pred = np.array([[0.9434484 ]
,[0.3787447 ]
,[0.87870705]
,[0.7575223 ]
,[0.39714795]])
np.round(pred)
Out[37]:
array([[1.],
[0.],
[1.],
[1.],
[0.]])
如果結(jié)果不是一個概率,那么:
def sigmoid(x):
return 1 / (1 + math.exp(-x))
必須用于將其縮放到0-1比例