如何使用“_xgb.Booster”"model_fit" 由防风草函数 boost_tree 渲染的对象来计算提升曲线和等分提升图?
How can I calculate lift curves and decile lift charts using "_xgb.Booster" "model_fit" objects rendered from parsnip function boost_tree?
我有这段代码呈现“_xgb.Booster”“model_fit”对象类。我应该,但我不确定如何在此处提供带有数据的完整可重现示例代码!
xgb <- boost_tree(mode = "classification",
trees = 100,
mtry = 0.7,
learn_rate = 0.15,
tree_depth = 10,
sample_size = 1) %>%
set_engine("xgboost") %>%
fit(Y ~ ., data = train)
如何使用此 xgb 对象计算提升曲线和等分提升图?
一旦您的数据采用示例数据集 two_class_example
中的形式,您就可以使用 lift_curve()
函数来计算它。然后就可以用提升曲线做可视化了。
library(tidymodels)
two_class_lift <- two_class_example %>%
lift_curve(truth, Class1)
two_class_lift %>%
autoplot()
two_class_lift %>%
group_by(.percent_tested = cut_interval(.percent_tested, n = 10)) %>%
summarise(.lift = mean(.lift, na.rm = TRUE)) %>%
ggplot(aes(.percent_tested, .lift)) +
geom_col() +
theme_bw() +
labs(x = "% Tested", y = "Lift")
#> `summarise()` ungrouping output (override with `.groups` argument)
由 reprex package (v0.3.0.9001)
于 2020-08-26 创建
如果您需要帮助从您的 xgboost 模型中获得预测,check out this article at tidymodels.org
。
我有这段代码呈现“_xgb.Booster”“model_fit”对象类。我应该,但我不确定如何在此处提供带有数据的完整可重现示例代码!
xgb <- boost_tree(mode = "classification",
trees = 100,
mtry = 0.7,
learn_rate = 0.15,
tree_depth = 10,
sample_size = 1) %>%
set_engine("xgboost") %>%
fit(Y ~ ., data = train)
如何使用此 xgb 对象计算提升曲线和等分提升图?
一旦您的数据采用示例数据集 two_class_example
中的形式,您就可以使用 lift_curve()
函数来计算它。然后就可以用提升曲线做可视化了。
library(tidymodels)
two_class_lift <- two_class_example %>%
lift_curve(truth, Class1)
two_class_lift %>%
autoplot()
two_class_lift %>%
group_by(.percent_tested = cut_interval(.percent_tested, n = 10)) %>%
summarise(.lift = mean(.lift, na.rm = TRUE)) %>%
ggplot(aes(.percent_tested, .lift)) +
geom_col() +
theme_bw() +
labs(x = "% Tested", y = "Lift")
#> `summarise()` ungrouping output (override with `.groups` argument)
由 reprex package (v0.3.0.9001)
于 2020-08-26 创建如果您需要帮助从您的 xgboost 模型中获得预测,check out this article at tidymodels.org
。