Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upupdate.train making .weights an independent variable when method = 'ranger' #935
Comments
|
Please let me know if there is something more I should include @topepo |
|
Sorry, just now rotating back to It is fixed but, to be honest, I'll be merging PRs and fixing bugs until the weekend. I would wait until then before testing. library(caret)
#> Loading required package: lattice
#> Loading required package: ggplot2
grid <- expand.grid(mtry = 1:2,
min.node.size = c(5, 10, 15),
splitrule = "variance" )
ctrl <- trainControl(method = "cv",
number = 5)
## define response for model
response <- iris$Sepal.Length / iris$Sepal.Width
## define case.weights for ranger
wgt <- iris$Sepal.Width
## fit initial train using ranger
trn.ranger <- train( y = response,
x = iris[, 3:5],
weights = wgt,
method = "ranger",
tuneGrid = grid,
verbose = F,
trControl = ctrl,
num.trees = 20,
importance = "impurity")
varImp(trn.ranger) ## 3 features in model
#> ranger variable importance
#>
#> Overall
#> Petal.Width 100.00
#> Species 40.53
#> Petal.Length 0.00
trn.ranger$bestTune ##bestTune is mtry=1, min.node.size = 10
#> mtry splitrule min.node.size
#> 3 1 variance 15
## update to choose different bestTune
trn.ranger.update <- update(trn.ranger, param = list(mtry = 2,
splitrule = "variance",
min.node.size = 15))
varImp(trn.ranger.update) ## new 4th feature is _no longer_ .weights
#> ranger variable importance
#>
#> Overall
#> Petal.Length 100.00
#> Petal.Width 61.78
#> Species 0.00Created on 2018-11-14 by the reprex package (v0.2.1) |
As the title says. I am trying to override the train object $bestTune to get a different $finalModel for prediction. I am not entirely sure if this should be placed here or with ranger. Thanks.
Minimal, reproducible example:
Session Info: