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 634 forks source link

Makes sure ranger method can generate grid of length 1. #1307

Closed carloscinelli closed 1 year ago

carloscinelli commented 2 years ago

Currently, ranger 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 = "ranger", trControl = trainControl(method = "none"))
# Error: Only one model should be specified in tuneGrid with no resampling

This was happening because the minimal grid it was creating has length 2, as it was passing both srule and "extratrees" to expand.grid regardless of the argument len.

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

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