0

I have a problem with a rMarkdown transformation.

Basically, I have to report the results of a Neural Net.

After the transformation in a pdf file the document is full of Neural net's calculations.

I have included this chunk


title: "Monitoring hydraulic systems"

output: pdf_document


{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
{r echo=FALSE, message=FALSE, warning=FALSE}

nNGrid=expand.grid(size=seq(1,9,1),decay=seq(0.1,1,0.1))


neuralNetwork= train(Class ~.,data=training_norm, method="nnet",
                     trControl=reg_Control,tuneGrid=nNGrid)


nNPredictions = predict(neuralNetwork,newdata=testing_norm)

ty<- confusionMatrix(nNPredictions,testing_norm$Class)

ty$table

to try to stop R from printing messages and warnings.

But this is what I get in my final pdf document:

weights:  67
initial  value 721.992732 
iter  10 value 519.008521
iter  20 value 488.124903
iter  30 value 456.941810
iter  40 value 330.558805
iter  50 value 259.373044

It's about 500 pages of calculations!

How can I solve this??

I have to delete all those calculations from my final document.

Can anyone help please??

I forgot to mention that I have excluded verboseIter=T from my rg_Control. But it still doesn't work.

I don't know what to do!

For the sake of completeness this is my reg_COntrol


Tabella_per_previsioni$Class=factor(Tabella_per_previsioni$Class,                                               labels=c("Alterato","Ottimale","Pericolo"))

set.seed(32343)

reg_Control = trainControl("repeatedcv", number = 5, repeats=5, classProbs =T) 


inTrain = createDataPartition(y=Tabella_per_previsioni$Class,p=0.75, list=FALSE)

training = Tabella_per_previsioni[inTrain,]

testing = Tabella_per_previsioni[-inTrain,]

train_stats <- preProcess(training, method="range")

training_norm <- predict(train_stats, training)

testing_norm <- predict(train_stats, testing)

Forgot to mention I'm using Caret.

Fabulus16
  • 17
  • 5
  • 2
    could you put a reproducible example so that we can test things and have a better understanding of your problem? – bretauv Sep 11 '19 at 17:05
  • Hi @bretauv, first of all thanks for your answer! I have edited my question so you can have a better understanding of the problem. What do you think? – Fabulus16 Sep 12 '19 at 07:18
  • Thanks for editing but what I mean by a reproducible example is the code for the whole markdown (not your whole document but just a code that we can put in R Studio and that runs fine), including the YAML for example. Not sure if it's clear, tell me – bretauv Sep 12 '19 at 07:21
  • Sorry @bretauv but I don't understand! :-( – Fabulus16 Sep 12 '19 at 07:24
  • If I copy the code you put in your question, it will not work because a R markdown document needs some obligatory parts in order to work well. If you create a new markdown document, there will be some code created automatically that aims to define the output (pdf, html...) and other settings. I would like you to add this code to the one you already put, so that when I copy it, it runs perfectly without any modification needed. Do you understand ? ;-) – bretauv Sep 12 '19 at 07:29
  • Thanks @bretauv I understand now! Does this work for you now??(I have edited my question again) – Fabulus16 Sep 12 '19 at 07:37
  • As it is mentioned in this other question, [https://stackoverflow.com/questions/30810476/suppress-console-output-in-r-markdown-but-keep-plot?rq=1] I have tried wrapping my object in the invisible function. But it still doesn't work! I have tried wrapping my train function.. – Fabulus16 Sep 12 '19 at 07:41
  • Sometimes wrapping the code that prints to the console in a `a <- capture.output({neuralNetwork <- train(...)})` helps – David Sep 12 '19 at 07:55
  • Thanks @David, I will try with this solution. – Fabulus16 Sep 12 '19 at 08:01
  • could you add the packages you're using ? – bretauv Sep 12 '19 at 08:19
  • I'm using Caret! @bretauv – Fabulus16 Sep 12 '19 at 08:29

1 Answers1

0

I have sorted everything out with David's suggestion.

"Sometimes wrapping the code that prints to the console in a

a <- capture.output({neuralNetwork <- train(...)})

helps".

Fabulus16
  • 17
  • 5