我想实现FBeta_Score()的的MLmetrics [R包:
FBeta_Score <- function(y_true, y_pred, positive = NULL, beta = 1) {
Confusion_DF <- ConfusionDF(y_pred, y_true)
if (is.null(positive) == TRUE)
positive <- as.character(Confusion_DF[1,1])
Precision <- Precision(y_true, y_pred, positive)
Recall <- Recall(y_true, y_pred, positive)
Fbeta_Score <- (1 + beta^2) * (Precision * Recall) / (beta^2 * Precision +
Recall)
return(Fbeta_Score)
}
Run Code Online (Sandbox Code Playgroud)
在H2O分布式随机森林模型中,我想在训练阶段使用该custom_metric_func选项对其进行优化.该h2o.randomForest()函数的帮助文档说:
参考自定义评估函数,格式为:'language:keyName = funcName'
但我不明白如何直接从R中使用它以及我应该在stopping_metric选项中指定的内容.
任何帮助,将不胜感激!
让我们用假数据创建一个矩阵:
data_ex <- data.frame(y = runif(5,0,1), a1 = runif(5,0,1), b2 = runif(5,0,1),
c3 = runif(5,0,1), d4 = runif(5,0,1))
> data_ex
y a1 b2 c3 d4
1 0.162 0.221 0.483 0.989 0.558
2 0.445 0.854 0.732 0.723 0.259
3 0.884 0.041 0.893 0.985 0.947
4 0.944 0.718 0.338 0.238 0.592
5 0.094 0.867 0.026 0.334 0.314
Run Code Online (Sandbox Code Playgroud)
该模型的公式如下:
forml <- as.formula("y ~ a1 + b2 + a1:c3:d4 + a1:c3 + a1:b2 + a1:b2:c3")
> forml
y ~ a1 + b2 + a1:c3:d4 …Run Code Online (Sandbox Code Playgroud)