r R脚本采用H2o模型权重和偏差,并通过NeuralNetTools旧的变量重要性函数发送它们......并且第一个ti

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r R脚本采用H2o模型权重和偏差,并通过NeuralNetTools旧的变量重要性函数发送它们......并且第一个ti相关的知识,希望对你有一定的参考价值。

#Rscript processModel.R
#http://rpackages.ianhowson.com/cran/NeuralNetTools/man/olden.html
#https://cran.r-project.org/web/packages/nnet/nnet.pdf
library(NeuralNetTools)
library(h2o)
library(jsonlite)

model_id <- 'deeplearning-f168835d-9e6e-4170-b881-fb5f214f302b'

localH2O <- h2o.init()
model <- h2o.getModel(model_id)
model_param <- slot(model, 'allparameters')
hidden_layers <- model_param[['hidden']]
layer_count <- length(hidden_layers) + 1
struct <- c()
weights <- list()

wts_in <- c()
for(i in 1:layer_count){
    weights_df <- as.data.frame(h2o.weights(model, i))
    nueron_count <- length(weights_df)
    struct <-c(struct, nueron_count)
    biases_df <- as.data.frame(h2o.biases(model, i))
    #nnet structure: The first value in each element of the list is the weight from the bias layer
    names(biases_df) <- c('B1')
    weights_df <- cbind(biases_df, weights_df)
    weights[[i]] = weights_df
    wts_in <- c(wts_in, t(weights[[i]]), recursive = TRUE)
}
struct <-c(struct, 1)
x_names <- names(weights[[1]])
x_names <- x_names[-1]

importances <- olden(wts_in, struct, x_lab=x_names, bar_plot=FALSE)
importance_json <- toJSON(importances, pretty=TRUE, dataframe='rows')
print(importance_json)
write(importance_json, file="./importances.json")

以上是关于r R脚本采用H2o模型权重和偏差,并通过NeuralNetTools旧的变量重要性函数发送它们......并且第一个ti的主要内容,如果未能解决你的问题,请参考以下文章

R:从 h2o.randomForest() 和 h2o.gbm() 绘制树

R语言使用DALEX包的model_performance函数对h2o包生成的多个算法模型进行残差分布分析并可视化每个模型的残差反向累积分布图

R基于H2O包构建深度学习模型实战

R语言基于h2o包构建二分类模型:使用h2o.gbm构建梯度提升机模型GBM使用h2o.auc计算模型的AUC值

R语言使用DALEX包的variable_importance函数对h2o包生成的多个算法模型进行特征重要度分析并可视化对比差异(feature importance)

R语言基于h2o包构建二分类模型:使用h2o.randomForest构建随机森林模型使用h2o.auc计算模型的AUC值