knitr and plotting neural networks

前端 未结 2 1889
暖寄归人
暖寄归人 2021-01-12 20:05

I\'m trying to plot some neural network outputs, but I\'m not getting any result. Plotting normal stuff like plot(iris) works fine, but there\'s something about

2条回答
  •  花落未央
    2021-01-12 20:12

    I think the issue is that for objects of class nn, plot uses a parameter rep. If rep is not defined, all repetitions are plotted in separate windows (when run outside of RMarkdown). If rep = "best", only the plot with the smallest error is generated. So this should work:

    ```{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")
    ```
    

    See ?plot.nn.

提交回复
热议问题