在火车上使用您自己的模型(插入包)?

时间:2015-10-16 16:41:32

标签: r r-caret

我正在尝试使用来自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,:Stopping另外:警告信息:1:In   eval(expr,envir,enclos):Training1的模型拟合失败:   mprior.size = 2方法$ fit中的错误(x = x,y = y,wts = wts,param =   tuneValue,lev = obsLevels,:unused arguments(wts = wts,last =   最后,classProbs = classProbs,type =“Regression”)

     

2:在nominalTrainWorkflow中(x = x,y = y,wts = weight,info =   trainInfo:重采样性能中缺少值   的措施。

2 个答案:

答案 0 :(得分:3)

显然,即使我从不使用它们,我也必须将参数放在函数中:

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)}

答案 1 :(得分:0)

你的函数bms()似乎不存在......