我正在使用Caret软件包使用“nnet”方法来训练模型。它正在工作,但我需要查看在隐藏层中使用的权重。
当我们直接使用nnet函数时,这是可能的:

model<-nnet(Data[5:8], Data[4],size=10,maxit=100000,linout=T,decay=0.1)
model$wts
 [1]  9.160050e-01  1.184379e+00 -1.201645e+00  1.041427e+00 -2.367287e-03  6.861753e+00  1.223522e+00 -1.875841e+01 -1.233203e-02
[10]  5.281464e-01 -1.605204e+00  1.497933e+00 -2.882815e+00 -1.511277e+01  2.732411e-01 -2.999315e+01  1.498460e-01 -9.405826e-01
[19] -2.800337e+00  9.600647e-02  1.588405e+00 -2.106175e+00 -8.807753e+00  2.762392e+01  2.091118e-01  3.265564e+01  6.516821e-01
[28]  1.304455e-01 -7.633166e+00  1.017017e-02  6.366411e+01 -2.902564e-02  1.376147e-01 -8.353788e+00  6.376588e-04  5.995577e+00
[37]  1.176301e+01 -8.569926e+00  1.971122e+01 -2.358067e-01  3.971781e+01  1.940421e-01  1.755913e-01 -5.817047e+00  1.988909e-03
[46]  1.408106e+00 -1.549250e+00  1.757245e+01 -5.760102e+01  1.001197e+00 -5.493371e+00  4.786298e+00  6.049659e+00 -1.762611e+01
[55] -9.598485e+00 -1.716196e+01  6.477683e+00 -1.971476e+01  4.468062e+00  2.125993e+01  4.683170e+01

使用插入符号包装时如何查看重量?
mynnetfit <- train(DC ~ T+c+f+h, data = Data1, method = "nnet",
    maxit = 1000, tuneGrid = my.grid, trace = T, linout = 1, trControl = ctrl)

最佳答案

模型对象mynnetfit具有finalModel组件,该组件属于nnet类。然后,您可以coef(mynnetfit$finalModel)获取节点的权重。

例如

library(caret)

## simulate data
set.seed(1)
dat <- LPH07_2(100, 20)

mod <- train(y ~ ., data=dat, method="nnet", trace=FALSE, linout=TRUE)

coef(mod$finalModel)

    b->h1      i1->h1      i2->h1      i3->h1      i4->h1      i5->h1      i6->h1      i7->h1      i8->h1      i9->h1
 -0.7622230   8.5760791   9.6162685 -13.0549859   5.3306854   8.1679126   3.1832575  -5.4354694   4.8410017  -6.3811887
    i10->h1     i11->h1     i12->h1     i13->h1     i14->h1     i15->h1     i16->h1     i17->h1     i18->h1     i19->h1
  7.0813781   3.4709351   5.6444663   4.2530566   0.6594511   0.5579828  23.5802215   5.0381758  -0.4883967 -13.0613378
    i20->h1     i21->h1     i22->h1     i23->h1     i24->h1     i25->h1     i26->h1     i27->h1     i28->h1     i29->h1
 11.8905272  -0.2732984  -4.5190578  -2.3095693   0.8891562   1.7922645  -0.4666446  -1.0980723  -4.7742597  -5.1603453
    i30->h1     i31->h1     i32->h1     i33->h1     i34->h1     i35->h1     i36->h1     i37->h1     i38->h1     i39->h1
 -0.1285864   2.2160653   0.2990097  -5.1722264  -4.8375324   1.4537326  -1.6870400  -2.1019009   1.3542151   0.7036545
    i40->h1        b->o       h1->o
 -2.1592154  10.7700684 -27.4712736

关于r - 带有“nnet”的插入符号包可查看隐藏层的重量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23495761/

10-14 18:41