2

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.

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Alexis
  • 2,104
  • 2
  • 19
  • 40

1 Answers1

2

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.
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • 2
    Thank you for your time and answer, it works fine! You know I tried with `knn` but no matter if it's `TRUE, FALSE or NULL` it says that `something is wrong; all the Accuracy metric values are missing:`. Anyway it works great with `gbm`. – Alexis Jun 22 '20 at 20:25
  • 2
    Hi @Alexis, you are welcome. That error you see with ```knn```, it is not an output but an error message. Most likely you need to check you are training the model correctly.. You can also post it as a question, with a reproducible example... most likely there are other SO users who can help you with it :) – StupidWolf Jun 22 '20 at 20:29