简体   繁体   中英

generating tuning parameter for Caret in R

I've been trying to use the caret package to do k-folds validation of a model. I've run lm() to some success, but when I try and do it with caret it fails. steps:

 train_control <- trainControl(method="cv", number=10)


 grid <- expand.grid(.fL=c(0), .usekernel=c(FALSE))


 model <- train(FantasyPTS ~ Shoots + Height + Weight + Birthyear + 
              age + Draft_Year + Overall_Draft_Num + Draft_Team + Draft_Age + 
             GAA + SVPCT + GSAA + QS + QS. + RBS + GPS, data=nhlgoalies, trControl=train_control, method="lm", tuneGrid=grid)

results in

Error in train.default(x, y, weights = w, ...) : 
  The tuning parameter grid should have columns intercept

my understanding was always that the model itself should generate the intercept. I know from reading the docs it needs the parameter intercept but I don't know how to generate it before the model itself is created?

You dont give a link to a dataset, so I generate my one for example.

    ## Make data
ncol <- 3
Xs       <- matrix(rnorm(300*ncol), nrow = 300, ncol = ncol) %>% as.tibble()
Yvec     <- rnorm(300)
train_control <- trainControl(method="cv", number=10)

    ## Fit lm model using train
fit  <- train(x= Xs, y = Yvec, method = "lm",trControl = train_control)

So you just don't need to specify tuneGrid parameter and will be ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM