rr-caretgbm

Eliminate iteration information text in caret R


I am working on some ML algorithms on the classic Iris dataset. This is my code:

library(tidyverse)
library(caret)

dataset <- iris
tt_index <- createDataPartition(dataset$Sepal.Length, times = 1, p = 0.9, list = FALSE)
train_set <- dataset[tt_index, ]
test_set <- dataset[-tt_index, ]

model_glm <- train(Species ~., 
                   data = train_set,
                   method = "gbm")

My problem is that complex methods like gbm show the iteration text information, like this:

Iter   TrainDeviance   ValidDeviance   StepSize   Improve
     1        1.0986             nan     0.1000    0.3942
     2        0.8415             nan     0.1000    0.2644
     3        0.6641             nan     0.1000    0.1963
     4        0.5333             nan     0.1000    0.1489
     5        0.4325             nan     0.1000    0.1091

I tried to use suppressWarnings and suppressMessagesfunctions but the iteration information text still appears.

suppressMessages(model_glm <- train(Species ~., 
                   data = train_set,
                   method = "gbm"))

Please, do you know how to avoid that information text? Any help will be greatly appreciated.


Solution

  • This should do the trick:

    model_glm <- train(Species ~., 
                       data = train_set,
                       method = "gbm",verbose=FALSE)
    

    Explanation, inside gbm() which is called by caret, there is an option to set verbose=FALSE, so that the training information is not printed. These additional parameters can be passed to gbm() or any other model function called, and is normally referred as ... , and you can see it in vignette:

    ...: Arguments passed to the classification or regression routine
          (such as ‘randomForest’). Errors will occur if values for
          tuning parameters are passed here.