Loss函数

import numpy as np 

def L1(yhat,y):
    loss=np.sum(np.abs(y-yhat))
    return loss

def L2(yhat,y):
    loss=np.sum(np.power((y-yhat),2))
    return loss

yhat = np.array([.9, 0.2, 0.1, .4, .9])
y = np.array([1, 0, 0, 1, 1])
print("L1 = " + str(L1(yhat,y)))
print("L2 = " + str(L2(yhat,y)))

猜你喜欢

转载自blog.csdn.net/smoggyxhdz/article/details/81409357