Skip to content

Commit

Permalink
Makes sure ranger method can generate grid of length 1. (topepo#1307)
Browse files Browse the repository at this point in the history
* Update ranger.R

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"))
```

This was happening because the minimal grid was a 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`.

* reup model file

---------

Co-authored-by: Max Kuhn <[email protected]>
  • Loading branch information
carloscinelli and topepo authored Mar 21, 2023
1 parent ffcf5ce commit 94ce7db
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion models/files/ranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ modelInfo <- list(label = "Random Forest",
classification = is.factor(y),
len = len),
min.node.size = ifelse( is.factor(y), 1, 5),
splitrule = c(srule, "extratrees"))
splitrule = c(srule, "extratrees")[1:min(2,len)])
} else {
srules <- if (is.factor(y))
c("gini", "extratrees")
Expand Down
Binary file modified pkg/caret/inst/models/models.RData
Binary file not shown.

0 comments on commit 94ce7db

Please sign in to comment.