1

R で LIME を使用して、目的の「count:poisson」で 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)

Poisson Explainer で Explain 関数を実行しようとすると、最終的にこのエラーがスローされます

Error: Unsupported model type
4

0 に答える 0