原理
实现
logloss的实现
def logloss(y_true, y_pred, eps=1e-15):
import numpy as np
# Prepare numpy array data
y_true = np.array(y_true)
y_pred = np.array(y_pred)
assert (len(y_true) and len(y_true) == len(y_pred))
# Clip y_pred between eps and 1-eps
p = np.clip(y_pred, eps, 1-eps)
loss = np.sum(- y_true * np.log(p) - (1 - y_true) * np.log(1-p))
return loss / len(y_true)
mlogloss的实现
from sklearn.metrics import log_loss
def Mutilogloss(y_true, y_pred, eps=1e-5):
allloss = []
for i in range(y_true.shape[1]):
loss = log_loss(y_true[:,i],y_pred[:,i])
allloss.append(loss)
return np.sum(allloss)/y_true.shape[1]