Reputation: 312
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?
Upvotes: 0
Views: 765
Reputation: 360
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.
Upvotes: 1