-2

我需要使用插入符号中的 nnet 训练的回归神经网络的每个节点的权重和偏差值。是否可以将此值导出到 csv?

4

1 回答 1

2

当然:

> library(caret)
> 
> set.seed(1)
> dat <- LPH07_2(200, noiseVars = 20)
> 
> set.seed(2)
> mod <- train(y ~ ., data = dat,
+              method = "nnet",
+              preProc = c("center", "scale"),
+              trControl = trainControl(method = "cv"),
+              trace = FALSE,
+              linout = TRUE)
> class(mod)
[1] "train"         "train.formula"
> class(mod$finalModel)
[1] "nnet.formula" "nnet"        
> coef(mod$finalModel)
      b->h1      i1->h1      i2->h1      i3->h1      i4->h1 
-25.4498023  -4.3103092  -6.1419006   9.9687175  18.5882001 
    i5->h1      i6->h1      i7->h1      i8->h1      i9->h1 
-8.9435466  -7.6128415  12.1248615  10.0708980 -10.0575266 
   i10->h1     i11->h1     i12->h1     i13->h1     i14->h1 
-8.4764064   5.9401545  -1.5913728   7.7627193   2.2499502 
  i15->h1     i16->h1     i17->h1     i18->h1     i19->h1 
3.8339322 -15.3320699  -3.2106348 -18.1776337  -5.2383470 
   i20->h1     i21->h1     i22->h1     i23->h1     i24->h1 
-0.4742562   1.7924703 -10.8341482   2.0669317 -10.7653807 
   i25->h1     i26->h1     i27->h1     i28->h1     i29->h1 
25.1267101  -2.3238480   5.0903482  16.5455288   4.3883148 
   i30->h1     i31->h1     i32->h1     i33->h1     i34->h1 
-6.6731234 -10.0256391 -15.4282063  -2.4175650  10.8461340 
   i35->h1     i36->h1     i37->h1     i38->h1     i39->h1 
12.1522709   7.2186336 -10.0399381  -6.8036466  -3.2871834 
   i40->h1        b->o       h1->o 
16.6448920  22.2094881 -65.2759878 

然后使用

out <- data.frame(value = coef(mod$finalModel),
                  param = names(coef(mod$finalModel)))
write.csv(out, file = "some.csv")

最大限度

于 2014-10-09T12:44:39.543 回答