gpt4 book ai didi

具有许多功能的 R xgboost 重要性图

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

我正在尝试 Kaggle 房价挑战:https://www.kaggle.com/c/house-prices-advanced-regression-techniques

这是我写的脚本

train    <- read.csv("train.csv")
train$Id <- NULL
previous_na_action = options('na.action')
options(na.action = 'na.pass')
sparse_matrix <- sparse.model.matrix(SalePrice~.-1,data = train)
options(na.action = previous_na_action)
model <- xgboost(data = sparse_matrix, label = train$SalePrice, missing = NA, max.depth = 6, eta = 0.3, nthread = 4, nrounds = 16, verbose = 2, objective = "reg:linear")
importance <- xgb.importance(feature_names = sparse_matrix@Dimnames[[2]], model = model)
print(xgb.plot.importance(importance_matrix = importance))

数据有 70 多个特征,我使用了 xgboostmax.depth = 6 和 nrounds = 16。

我得到的重要性图非常困惑,我如何才能只查看前 5 个特征或其他内容。

enter image description here

最佳答案

查看 xgb.plot.importancetop_n 参数。它完全符合您的要求。

# Plot only top 5 most important variables.
print(xgb.plot.importance(importance_matrix = importance, top_n = 5))

编辑:仅适用于 xgboost 的开发版本。替代方法是这样做:

print(xgb.plot.importance(importance_matrix = importance[1:5]))

关于具有许多功能的 R xgboost 重要性图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39371738/

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