gpt4 book ai didi

r - 如何在 r 中的 h2o.automl 排行榜中打印所有模型的可变重要性

转载 作者:行者123 更新时间:2023-12-04 01:47:09 25 4
gpt4 key购买 nike

我在 R 中使用 H2o 包的 automl() 函数进行回归。

假设我使用名称“aml”来构建模型。

aml <- h2o.automl(x=x, y=y, training_frame = train_set,
max_models = 20, seed = 1,
keep_cross_validation_predictions = TRUE)

automl() 的排行榜显示了表现最好的模型。我能够通过 h2o.varimp() 函数打印预测变量的重要性,并使用 h2o.varimp_plot() 函数绘制相同的图表,仅用于领导者模型(automl 给出的最佳模型功能)。

h2o.varimp(aml@leader)
h2o.varimp_plot(aml@leader)

有没有办法打印排行榜中所有模型的预测变量的变量重要性,并使用上述两个函数绘制图表?

最佳答案

Stacked Ensembles(通常是领导者模型)尚不支持变量重要性 (JIRA here)。然而,其余模型的变量重要性可以在排行榜中的模型 id 循环中检索。请参阅下面的 R 代码。

library(h2o)
h2o.init()

# Import a sample binary outcome train/test set into H2O
train <- h2o.importFile("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv")

# Identify predictors and response
y <- "response"
x <- setdiff(names(train), y)

# For binary classification, response should be a factor
train[,y] <- as.factor(train[,y])

# Run AutoML for 10 models
aml <- h2o.automl(x = x, y = y,
training_frame = train,
max_models = 10,
seed = 1)

# View the AutoML Leaderboard
lb <- aml@leaderboard
print(lb, n = nrow(lb))

# Get model ids for all models in the AutoML Leaderboard
model_ids <- as.data.frame(lb$model_id)[,1]

# View variable importance for all the models (besides Stacked Ensemble)
for (model_id in model_ids) {
print(model_id)
m <- h2o.getModel(model_id)
h2o.varimp(m)
h2o.varimp_plot(m)
}

关于r - 如何在 r 中的 h2o.automl 排行榜中打印所有模型的可变重要性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54852453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com