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

标签 r customization package random-forest h2o

我正在尝试实现 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/

相关文章:

r - R 有没有办法将行组合起来得出总计/平均值?

jquery - 自定义我网站上的滚动条

android - 以编程方式获取 PNG 或 BMP 格式的 Android 包图标

r - 如何使用 `td`软件包中的 `tempdisagg`命令将每月数据分解为每日数据频率?

r - 识别ggplot2 QQ图中的点?

android - 操作栏微调器定制

emacs - 自定义 emacs 24 ELPA 工作位置

python - 在谷歌云函数中访问用户定义的包(ModuleNotFoundError : No module named. ..)

python - 如何制作python包?

r - 使用条件在 r 中创建组合列表