在R中的插入符号中创建RMSLE指标 [英] Create RMSLE metric in caret in r

查看:154
本文介绍了在R中的插入符号中创建RMSLE指标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以为我提供以下帮助:我需要将带有插入符号包的xgboost训练模型更改为非默认指标RMSLE.默认情况下,插入符号和xgboost在RMSE中训练和度量.

Could someone please help me with the following: I need to change my xgboost training model with caret package to an undefault metric RMSLE. By default caret and xgboost train and measure in RMSE.

以下是代码行:

custom_summary = function(data, lev = NULL, model = NULL){
out = rmsle(data[, "obs"], data[, "pred"])
names(out) = c("rmsle")
out
}

创建控制对象

control = trainControl(method = "cv",  
                   number = 2,     
                   summaryFunction = custom_summary)

创建调整参数网格

grid = expand.grid(nrounds = 100, 
               max_depth = 6,          
               eta = 0.075,     
               gamma = 0, 
               colsample_bytree = 0.4, 
               min_child_weight = 2.25,
               subsample = 1)

cl = makeCluster(3, type="SOCK") #make clusters

registerDoSNOW(cl)  #register clusters

set.seed(1)

训练我的模型

caret4 =  train(price_doc~. - sub_area - id,
                    data=train.train,
                    method="xgbTree",
                    trControl=control, 
                    tuneGrid=grid, 
                    metric="rmsle",
                    maximize = FALSE)

而且我不断收到错误消息:{:任务1失败-找不到函数"rmsle""

推荐答案

我在项目中也遇到了相同的问题. 即使使用以下命令将Metrics程序包加载到内存中,也是如此.
图书馆(指标)

I also encountered the same issue in my project. This is even after loading the Metrics package in memory using the below command.
library(Metrics)

如果看到,则从另一个名为custom_summary的函数调用rmsle函数.它不是直接调用的. 因此,我从custom_summary函数中加载了Metrics软件包,它为我解决了这个问题.

If you see, rmsle function is being called from another function called custom_summary. It is not called directly. So I loaded the Metrics package from within the function custom_summary and it solved the issue for me.

因此,此处的custom_summary函数应类似于:

so here, the custom_summary function should look like:

custom_summary =函数(数据,lev = NULL,模型= NULL){
图书馆(指标)
out = rmsle(data [,"obs"],data [,"pred"])
名称(out)= c("rmsle")

}

custom_summary = function(data, lev = NULL, model = NULL) {
library(Metrics)
out = rmsle(data[, "obs"], data[, "pred"])
names(out) = c("rmsle")
out
}

这篇关于在R中的插入符号中创建RMSLE指标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆