直接从 R 实施自定义停止指标以在 H2O 模型训练期间进行优化

Implementing custom stopping metrics to optimize during training in H2O model directly from R

我正在尝试实施 FBeta_Score() of the 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()函数上传到后台。然后,此函数将 return 一个函数引用(这是一个字符串,其命名约定格式为 'language:keyName=funcName')。然后你可以传递给 custom_metric 参数。

例如:

custom_mm_func = h2o.upload_custom_metric(CustomRmseFunc, func_name="rmse", func_file="mm_rmse.py")

returns 具有以下值的函数引用:

> print(custom_mm_func)
python:rmse=mm_rmse.CustomRmseFuncWrapper

关于使用自定义指标作为停止指标的第二个问题,您可以在此处查看 jira 票证:https://0xdata.atlassian.net/browse/PUBDEV-5261

您可以找到有关如何使用自定义指标的更多详细信息 here