Using the following code with Knit HTML in Rstudio
---
title: "test"
output: html_document
---
```{r pressure, echo=FALSE}
library(caret)
tc <- trainControl(method="boot",number=25)
train = train(Species~.,data=iris,method="nnet",trControl=tc)
confusionMatrix(train)
```
How to avoid the train iteration print on my html file?
As suggested in @Swiss12000's comment, the argument trace = FALSE can be passed to train to suppress the messages.
This behaviour is not documented in ?train because the parameter is passed (via ...) to the method nnet. trace = FALSE will only work for methods that support this parameter. In other cases, the capture.output approach below might still be useful.
caret::train prints messages to stdout, unsolicitedly. That's nasty. The output can be suppressed by wrapping the expression in capture.output():
garbage <- capture.output(train <- train(Species~.,data=iris,method="nnet",trControl=tc))
Note that this is one of the cases where the differentce between the assignment operators matters: capture.output(train = train(... doesn't work, probably because the assignment is interpreted as an argument to train().
In order to additionally suppress the package startup messages, add the chunk option message = FALSE.
---
title: "test"
output: html_document
---
```{r echo=FALSE, message = FALSE}
library(caret)
tc <- trainControl(method = "boot",number = 25)
garbage <- capture.output(
train <- train(Species ~ ., data = iris, method = "nnet", trControl = tc))
confusionMatrix(train)
```
Output:
test
## Bootstrapped (25 reps) Confusion Matrix ## ## (entries are percentages of table totals) ## ## Reference ## Prediction setosa versicolor virginica ## setosa 33.8 0.0 0.0 ## versicolor 0.0 31.0 1.1 ## virginica 0.0 2.0 32.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With