gpt4 book ai didi

r - 随机森林模型的形状图

转载 作者:行者123 更新时间:2023-12-05 06:55:21 26 4
gpt4 key购买 nike

我想获取 Ranger/随机森林模型变量的 Shap Contribution,并在 R 中绘制这样的图:

beeswarm plots

我尝试使用以下库:DALEX、shapr、fastshap、shapper。我只能得到这样的情节: fastshap plot

有没有可能得到这样的情节?我试过 reticulate 包,但它仍然不起作用。

最佳答案

随机森林需要种植许多树。尽管可能,为树处理 TreeSHAP 需要大量内存和 CPU 能力。另一种方法是使用适用于所有类型模型的 Kernel SHAP 算法。

library(ranger)
library(kernelshap)
library(shapviz)

set.seed(1)
fit <- ranger(Sepal.Length ~ ., data = iris,)

# Step 1: Calculate Kernel SHAP values
# bg_X is usually a small (50-200 rows) subset of the data
s <- kernelshap(fit, iris[-1], bg_X = iris)

# Step 2: Turn them into a shapviz object
sv <- shapviz(s)

# Step 3: Gain insights...
sv_importance(sv, kind = "bee")
sv_dependence(sv, v = "Petal.Length", color_var = "auto")

SHAP summary plot SHAP dependence plot

免责声明:我写了“kernelshap”和“shapviz”

关于r - 随机森林模型的形状图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65391767/

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