【问题标题】:R h2o: examining the nodes on a deeplearning neuralnet modelR h2o:检查深度学习神经网络模型上的节点
【发布时间】:2021-01-11 21:34:57
【问题描述】:

我希望能够检查我的神经网络上的节点结构。具体来说,我使用 L1 和 L2 正则化,想知道我的权重有多少比例萎缩到零。我训练有素的神经网络是否使用每个节点,或者我可以使用更少的隐藏节点吗?那种东西。

这是一个玩具问题:

library(h2o)
h2o.init()

x <-seq(-10,10,by=0.0002)
y <- dnorm(x,sd=2)*sin(2*x)     # The function the neuralnet will attempt to fit
plot(x,y,type="l")

df <- data.frame(x=x,y=y)
df2 <- as.h2o(df)
model <- h2o.deeplearning(df2,
                x=1,
                y=2,
                hidden=c(200,100,50,10,5),  # way more hidden nodes than it needs
                l1=0.0000001,           # regularisation to reduce the number of unnecessary nodes
                l2=0.0000001,
                activation="Tanh",
                export_weights_and_biases=TRUE)

P <- as.data.frame(h2o.predict(model,df2))

lines(x,P$predict,col=2)
legend("topleft",legend=c("Training data","nn output"),col=c(1,2),lwd=1)

h2o 中是否有一个函数可以为我提供所有权重的信息?

(我试过 h2o.weights(),它似乎只给了我第一层)

如果模型是 S4 对象,那么检查 S4 对象的方法是什么?

额外问题:在 h2o 中是否有任何可视化节点结构的能力?

【问题讨论】:

    标签: r deep-learning h2o


    【解决方案1】:

    h2o.weights() 函数默认返回第一层权重,作为 H2OFrame。您可以通过更改matrix_id 参数来获得任意层。

    一些例子:

    > h2o.weights(model)
               x
    1  0.3520632
    2  0.5535296
    3 -0.4793063
    4  0.3828013
    5 -0.3253765
    6  0.7234487
    
    [200 rows x 1 column]
    
    
    > h2o.weights(model, matrix_id = 5)
              C1        C2         C3         C4         C5         C6          C7          C8         C9         C10
    1  0.7233770 0.7793967 -1.4486042 -0.8187707  0.8667952  1.0290394  0.26213858  0.02487412  0.3342296  0.39383927
    2  0.4528885 0.2434976  0.5963052  0.9640941 -0.4480562 -0.1976745 -0.63002998  0.17428128 -0.9241131  0.13199258
    3 -0.5477357 0.4918589 -0.7991062 -0.6445754  0.3618000  0.1324274  0.60856968 -0.35876906 -0.0655041  0.21673690
    4 -0.3147219 0.2541574 -0.5886489 -0.9993418  0.3042635  0.4107490 -0.08639368 -1.11863077  0.8755589 -0.06117416
    5 -0.7028044 0.4625969 -0.3838535 -0.6484048 -0.6975272  0.2663548 -0.17953268  0.14127040 -0.6482394 -0.04426440
    
    
    
    > hidden <- c(200,100,50,10,5)
    > for (i in 1:(length(hidden) + 1)) {
    +   print(dim(h2o.weights(model, matrix_id = i)))
    + }
    [1] 200   1
    [1] 100 200
    [1]  50 100
    [1] 10 50
    [1]  5 10
    [1] 1 5
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-31
      • 1970-01-01
      • 2020-05-15
      • 2018-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      相关资源
      最近更新 更多