小编sha*_*msy的帖子

使用自定义评分函数时,GridSearchCV 可以使用 Predict_proba 吗?

我正在尝试使用自定义评分函数来计算多类对数损失与真实值和 Predict_probay 数组。有没有办法让 GridSearchCV 使用这个评分函数?

def multiclass_log_loss(y_true, y_pred):
Parameters
----------
y_true : array, shape = [n_samples]
        true class, intergers in [0, n_classes - 1)
y_pred : array, shape = [n_samples, n_classes]

Returns
-------
loss : float
"""
eps=1e-15
predictions = np.clip(y_pred, eps, 1 - eps)

# normalize row sums to 1
predictions /= predictions.sum(axis=1)[:, np.newaxis]

actual = np.zeros(y_pred.shape)
n_samples = actual.shape[0]
actual[np.arange(n_samples), y_true.astype(int)] = 1
vectsum = np.sum(actual * np.log(predictions))
loss = -1.0 / n_samples * vectsum
return loss
Run Code Online (Sandbox Code Playgroud)

我看到有多个选项,score_func、loss_func …

scikit-learn

5
推荐指数
1
解决办法
3951
查看次数

标签 统计

scikit-learn ×1