如何获得R h2o deeplearning包中每个参数百分比的贡献?

时间:2015-05-23 13:47:07

标签: r parameters deep-learning h2o

如何在R h2o deeplearning包中获得参数贡献的每个百分比?

library(h2o)
localH2O = h2o.init(ip = "localhost", port = 54321, startH 2O = TRUE)
irisPath = system.file("extdata", "iris.csv", package = "h2o")
iris.hex = h2o.importFile(localH2O, path = irisPath)
h2o.deeplearning(x = 1:4, y = 5, data = iris.hex, activation = "Tanh")
h2o.shutdown(localH2O)

1 个答案:

答案 0 :(得分:1)

在构建模型时,请添加以下条件:variable_importance = T

这将确保在构建模型时,它将返回变量重要性。

在R的深度学习演示中,这需要您修改模型构建过程。首先,运行以下代码启动演示:

library(h2o)
conn <- h2o.init(nthreads = -1)
demo(h2o.deeplearning)

然后,通过添加前面提到的条件来调整启动模型构建的代码:

model = h2o.deeplearning(x = setdiff(colnames(prostate.hex), c("ID","CAPSULE")), y = "CAPSULE", training_frame = prostate.hex, activation = "Tanh", hidden = c(10, 10, 10), epochs = 10000, variable_importances = T)

最后,您可以执行以下操作来获取变量重要性:

> h2o.varimp(model)
Variable Importances:
  variable relative_importance scaled_importance percentage
1      PSA            1.000000          1.000000   0.175660
2      VOL            0.937293          0.937293   0.164645
3  GLEASON            0.930565          0.930565   0.163463
4      AGE            0.799607          0.799607   0.140459
5    DCAPS            0.793741          0.793741   0.139429
6    DPROS            0.703781          0.703781   0.123626
7     RACE            0.527824          0.527824   0.092718

希望这有帮助!