R: how to round weights digits in plot.nn()?

Viewed 83

I am trying to plot my neural network and I am wondering how can I round the weights to 3 digits.

library(neuralnet)
set.seed(0)

x = matrix(rnorm(100, 0, 5), ncol=4)
y = rnorm(25, 100, 20)
data = data.frame(y, x)
nn.model = neuralnet(y~., data, linear.output=T, stepmax = 1e+06)

plot(nn.model)

I've tried mapply(round) but it didn't work out on lists as neuralnet model generates. Any suggestion is appreciated!

1 Answers

Like this:

nn.model$weights[[1]] <- lapply(nn.model$weights[[1]], function(x) round(x, 3))
plot(nn.model)

enter image description here

Related