采用替代性能指标的R-caret模型评估

采用替代性能指标的R-caret模型评估,r,r-caret,evaluation-function,R,R Caret,Evaluation Function,我正在使用R的caret包进行一些网格搜索和模型评估。我有一个自定义的评估指标,它是绝对误差的加权平均值。权重是在观察级别分配的 X <- c(1,1,2,0,1) #feature 1 w <- c(1,2,2,1,1) #weights Y <- 1:5 #target, continuous #assume I run a model using X as features and Y as target and get a vector of predictions

我正在使用R的caret包进行一些网格搜索和模型评估。我有一个自定义的评估指标,它是绝对误差的加权平均值。权重是在观察级别分配的

X <- c(1,1,2,0,1) #feature 1
w <- c(1,2,2,1,1) #weights
Y <- 1:5 #target, continuous

#assume I run a model using X as features and Y as target and get a vector of predictions

mymetric <- function(predictions, target, weights){

v <- sum(abs(target-predictions)*weights)/sum(weights) 
return(v)
}

X您不能将权重直接传递给summary函数,这是一个疏忽,因为您可以将它们传递给建模函数。如果基础模型包含权重,则使用它们生成预测值

我将把它添加到下一个版本中


最大值

Hi。。只是为了确认是否在新版本的插入符号中进行了此更改?我使用的是caret-6.0-58,它的参数没有确认权重-代码失败,将权重添加到摘要函数中,并出现错误-“error in FUN(左、右):二进制运算符的非数值参数”