我正在尝试在 R 中使用 LIME 来解释具有目标“计数:泊松”的 xgboost 模型。对于标准的“reg:linear”来说,它似乎工作得很好。有没有解决的办法?这个问题以前在这里被问过,但没有被接受的答案。
石灰的 R 版本可以用 count:poisson 目标函数解释 xgboost 模型吗?
require(dplyr)
require(xgboost)
require(lime)
#generate data
df_train <- data.frame(
x1 = rnorm(n = 1000),
x2 = rnorm(n = 1000),
x3 = rnorm(n = 1000)) %>%
mutate(y = rpois(1000, pmax(0, x1 + 2*x2 - 0.5*x3)))
df_hold_out <- data.frame(
x1 = rnorm(n = 5),
x2 = rnorm(n = 5),
x3 = rnorm(n = 5)) %>%
mutate(y = rpois(5, pmax(0, x1 + 2*x2 - 0.5*x3)))
#set matrix
dmat <- xgb.DMatrix(data = as.matrix(df_train[, c("x1", "x2", "x3")]), label = df_train[["y"]])
#train with linear objective
mod_linear <- xgboost(data = dmat, nrounds = 100, params = list(objective = "reg:linear"))
#train with poisson objective
mod_poisson <- xgboost(data = dmat, nrounds = 100, params = list(objective = "count:poisson"))
#explain linear model
explainer_linear <- lime(x = df_hold_out, model = mod_linear, n_bins = 5)
explanation_linear <- lime::explain(
x = df_hold_out[, c("x1", "x2", "x3")],
explainer = explainer_linear,
n_permutations = 5000,
dist_fun = "gower",
kernel_width = .75,
n_features = 10,
feature_select = "highest_weights")
#plot
plot_features(explanation_linear)
#explain poisson model
explainer_poisson <- lime(x = df_hold_out, model = mod_poisson, n_bins = 5)
explanation_poisson <- lime::explain(
x = df_hold_out[, c("x1", "x2", "x3")],
explainer = explainer_poisson,
n_permutations = 5000,
dist_fun = "gower",
kernel_width = .75,
n_features = 10,
feature_select = "highest_weights")
#plot
plot_features(explanation_poisson)
试图在泊松解释器上运行解释函数最终会抛出这个错误
Error: Unsupported model type