Knitr and Neural Networking

I am trying to build some outputs of a neural network, but I am not getting any result. Building a normal material like this plot(iris)works fine, but there is something about an object neuralnetwork()that doesn't seem to have the same meaning.

My file looks like this:

---
title: "stack"
author: "stack"
date: "today"
output:
  pdf_document: default
  html_document: default
---


```{r}
library(neuralnet)
AND <- c(rep(0,3),1)
binary.data <- data.frame(expand.grid(c(0,1), c(0,1)), AND)
net <- neuralnet(AND~Var1+Var2,  binary.data, hidden=0,err.fct="ce", linear.output=FALSE)
plot(net)
```

And I do not get any output. There is nothing else in the same file. Any thoughts?

+4
source share
2 answers

This issue has been submitted and answered previously in the repository rmarkdown . Here I am only trying to explain the technical reason why this did not work.

On the help page ?neuralnet::plot.nn:

Usage

    ## S3 method for class 'nn'
    plot(x, rep = NULL, x.entry = NULL, x.out = NULL,
        ....


Arguments

  ...

  rep   repetition of the neural network. If rep="best", the repetition
        with the smallest error will be plotted. If not stated all repetitions
        will be plotted, each in a separate window.

From the source code (v1.33):

> neuralnet:::plot.nn
function (x, rep = NULL, x.entry = NULL, x.out = NULL, radius = 0.15, 
    .... 
{
    ....
    if (is.null(rep)) {
        for (i in 1:length(net$weights)) {
            ....
            grDevices::dev.new()
            plot.nn(net, rep = i, 
                    ....
        }
    }

, .... . , rep, neuralnet:::plot.nn . knitr,

  • , ( dev.control(displaylist = 'enable'));
  • knitr ; , , knitr. , .

neuralnet, drop dev.new() , , , .

if (interactive()) grDevices::dev.new()

, dev.new() , , , , . R / ( , , x11() quartz()), , .

interactive(), R, , ( , ) .

+7

, , nn, plot rep. rep , ( RMarkdown). rep = "best", . :

```{r}
library(neuralnet)
AND <- c(rep(0,3),1)
binary.data <- data.frame(expand.grid(c(0,1), c(0,1)), AND)
net <- neuralnet(AND~Var1+Var2,  binary.data, hidden=0,err.fct="ce", 
linear.output=FALSE)
plot(net, rep = "best")
```

. ?plot.nn.

+1

Source: https://habr.com/ru/post/1676425/


All Articles