topepo / caret

caret (Classification And Regression Training) R package that contains misc functions for training and plotting classification and regression models
http://topepo.github.io/caret/index.html
1.61k stars 632 forks source link

Makes sure `gam' method can generate grid of length 1. #1308

Closed carloscinelli closed 1 year ago

carloscinelli commented 2 years ago

Currently, the `gam' method gives an error if passed with trainControl(method = "none"). You can see the error here:

rm( list = ls())
n <- 1e3
x <- cbind(x = rnorm(n))
y <- c(x + rnorm(n))
train(x, y, method = "gam", trControl = trainControl(method = "none"))
# Error: Only one model should be specified in tuneGrid with no resampling

Note that the default behavior of trainControl(method = "none") is to set tuneLength = 1 and thus create a grid of length 1.

However, here the minimal grid it was creating always had length 2, as it was passing both TRUE and FALSE to the parameter `select,' which does not make sense if we want a grid of length 1.

The proposed change makes sure expand.grid will always have length 1, if len = 1.

(and this does not affect the behavior of anything else whenever len > 1)

topepo commented 1 year ago

@carloscinelli thanks for these