我可以使用插入符号twoClassSummary作为logLoss指标

时间:2016-03-01 17:15:45

标签: r r-caret

有没有办法将logLoss指标用于twoClassSummary?我已将multiClassSummarylogLoss一起使用。将multiClassSummary与某些方法一起使用,例如' nnet'对于logLoss的两个类问题似乎抛出错误:

Error in { : task 1 failed - "'n' must be a positive integer >= 'x'" 

1 个答案:

答案 0 :(得分:0)

就个人而言,我发现使用插头令人沮丧。我的意见是,试图拥有这样一个包罗万象的一揽子计划,同时一个崇高的目标,使其变得笨拙。

我编写了自己的logloss和多级logloss功能,你可以在这里找到。它依赖于CreateDataPartition的插入符号,但我可能会在下次更新源代码时将其删除。

devtools::install_github("alexwhitworth/glmEnsemble")

一个例子:

data(iris)
# indicator matrix of class membership
c_mat <- matrix(0, nrow=150, ncol=3)
c_mat[,1] <-ifelse(iris$Species == "setosa", 1, 0)
c_mat[,2] <-ifelse(iris$Species == "versicolor", 1, 0)
c_mat[,3] <-ifelse(iris$Species == "virginica", 1, 0)

# example predicted probability matrix
p_mat <- matrix(1/3, nrow=150, ncol=3)

# multiclass log-loss (I should make this exported this on the next update)
glmEnsemble:::multiclass_logloss(p_mat, c_mat)
[1] -1.098612
# two class log-loss
glmEnsemble::class_logloss(p_mat[,1], c_mat[,1])
[1] -0.3662041