机器学习:损失函数、经验风险最小化、结构风险最小化
程序员文章站
2024-02-13 14:30:16
...
from sklearn.metrics import zero_one_loss
y_true = [1,1,1,1,1,0,0,0,0,0]
y_pred = [0,0,0,1,1,1,1,1,0,0]
zero_one_loss(y_true,y_pred,normalize=False)
from sklearn.metrics import log_loss
y_true = [1,1,1,0,0,0]
# y_pred分布表示样本是0和1的概率
y_pred = [[0.1,0.9],
[0.2,0.8],
[0.3,0.7],
[0.7,0.3],
[0.8,0.2],
[0.9,0.1]]
log_loss(y_true,y_pred)