我正在尝试实现 FBeta_Score()
MLmetrics
R package :
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)
}
在 H2O distributed random forest model我想在训练阶段使用 custom_metric_func
选项对其进行优化。
h2o.randomForest()
函数的帮助文档说:
Reference to custom evaluation function, format: 'language:keyName=funcName'
但我不明白如何直接从 R 使用它以及我应该在 stopping_metric
选项中指定什么。
如有任何帮助,我们将不胜感激!
最佳答案
目前后端仅支持基于Python的自定义函数,可以通过 h2o.upload_custom_metric() 上传到后端功能。然后,该函数将返回一个函数引用(这是一个命名约定格式为 'language:keyName=funcName'
的字符串)。然后您可以将其传递给 custom_metric
参数。
例如:
custom_mm_func = h2o.upload_custom_metric(CustomRmseFunc, func_name="rmse", func_file="mm_rmse.py")
返回具有以下值的函数引用:
> print(custom_mm_func)
python:rmse=mm_rmse.CustomRmseFuncWrapper
关于使用自定义指标作为停止指标的第二个问题,您可以在此处关注 jira 票证:https://0xdata.atlassian.net/browse/PUBDEV-5261
您可以找到有关如何使用自定义指标的更多详细信息 here .
关于r - 直接从 R 实现自定义停止指标以在 H2O 模型训练期间进行优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51657527/