我试图使用Caret附带的包装中未包含的火车,但收到一个我无法弄清楚的错误,知道吗?我用following link开始

bmsMeth<-list(type="Regression",library="BMS",loop=NULL,prob=NULL)
prm<-data.frame(parameter="mprior.size",class="numeric",label="mprior.size")
bmsMeth$parameters<-prm
bmsGrid<-function(x,y,len=NULL){
out<-expand.grid(mprior.size=seq(2,3,by=len))
out
}
bmsMeth$grid<-bmsGrid
bmsFit<-function(x,y,param, lev=NULL) {bms(cbind(y,x),burn=5000,iter=100000,nmodel=1000,mcmc="bd",g="UIP",mprior.size=param$mprior.size)}
bmsMeth$fit<-bmsFit
bmsPred<-function(modelFit,newdata,preProcess=NULL,submodels=NULL){predict(modelFit,newdata)}
bmsMeth$predict<-bmsPred

library(caret)
data.train<-data.frame(runif(100),runif(100),runif(100),runif(100),runif(100))#synthetic data for testing
bms(cbind(data.train[,1],data.train[,-1]),burn=5000,iter=100000,nmodel=1000,mcmc="bd",g="UIP",mprior.size=2)#function out of caret is working

preProcess=c('center','scale')
myTimeControl <- trainControl(method = "timeslice",initialWindow = 0.99*nrow(data.train), horizon = 1, fixedWindow = FALSE)
tune <- train(data.train[,-1],data.train[,1],preProcess=preProcess,method = bmsMeth,tuneLength=2,metric= "RMSE",trControl =myTimeControl,type="Regression")


错误我得到:


train.default(data.train [,-1],data.train [,1],preProcess =
preProcess ,:正在停止另外:警告消息:1:在
eval(expr,envir,enclos):Training1的模型拟合失败:
mprior.size = 2方法错误$ fit(x = x,y = y,wts = wts,param =
tuneValue,lev = obsLevels,:未使用的参数(wts = wts,last =
最后,classProbs = classProbs,类型=“回归”)

2:在nominalTrainWorkflow(x = x,y = y,wts =重量,信息=
trainInfo:重采样性能中缺少值
措施。

最佳答案

显然,即使我从未使用过参数,我也只需将其放入函数中:

bmsFit<-function(x,y,param, lev=NULL, last, weights, classProbs, ...) {bms(data.frame(y,x),burn=5000,iter=100000,nmodel=1000,mcmc="bd",g="UIP",mprior.size=param$mprior.size)}

08-24 15:09