Skip to content

Commit 1580a0f

Browse files
authored
Merge pull request #1565 from exploratory-io/fix/chaid-partial-dependence
feat(chaid): partial dependence for Analytics Report (v16.0.16)
2 parents 7fa178e + 3323095 commit 1580a0f

11 files changed

Lines changed: 687 additions & 58 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: exploratory
22
Type: Package
33
Title: R package for Exploratory
4-
Version: 16.0.15
4+
Version: 16.0.16
55
Date: 2026-07-25
66
Authors@R: c(person("Hideaki", "Hayashi", email = "hideaki@exploratory.io", role = c("aut", "cre")), person("Hide", "Kojima", email = "hide@exploratory.io", role = c("aut")), person("Kan", "Nishida", email = "kan@exploratory.io", role = c("aut")), person("Kei", "Saito", email = "kei@exploratory.io", role = c("aut")), person("Yosuke", "Yasuda", email = "double.y.919.quick@gmail.com", role = c("aut")))
77
URL: https://github.com/exploratory-io/exploratory_func

R/build_catboost.R

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ exp_catboost <- function(df,
13771377
}
13781378

13791379
#' @export
1380-
glance.catboost_exp <- function(x, pretty.name = FALSE, ...) {
1380+
glance.catboost_exp <- function(x, pretty.name = FALSE, report_metrics = FALSE, ...) {
13811381
if ("error" %in% class(x)) {
13821382
return(data.frame(Note = x$message))
13831383
}
@@ -1390,9 +1390,15 @@ glance.catboost_exp <- function(x, pretty.name = FALSE, ...) {
13901390
rsq <- r_squared(actual, predicted)
13911391
n <- length(actual)
13921392
ret <- data.frame(r_squared = rsq, root_mean_square_error = root_mean_square_error, n = n)
1393+
if (isTRUE(report_metrics)) {
1394+
ret <- ret %>% dplyr::mutate(mean_absolute_error = mae(actual, predicted))
1395+
}
13931396
if (pretty.name) {
13941397
map <- list(`R Squared` = as.symbol("r_squared"), `RMSE` = as.symbol("root_mean_square_error"), `Rows` = as.symbol("n"))
13951398
ret <- ret %>% dplyr::rename(!!!map)
1399+
if (isTRUE(report_metrics)) {
1400+
ret <- ret %>% dplyr::rename(`MAE` = mean_absolute_error)
1401+
}
13961402
}
13971403
if (!is.null(x$inf_removed_rows) && x$inf_removed_rows > 0) {
13981404
ret$Note <- x$inf_removed_message
@@ -1444,7 +1450,7 @@ catboost_prediction_training_and_test <- function(x, binary_classification_thres
14441450

14451451
#' @export
14461452
#' @param type "importance", "evaluation", "conf_mat", "partial_dependence", "partial_binning", "evaluation_log"
1447-
tidy.catboost_exp <- function(x, type = "importance", pretty.name = FALSE, binary_classification_threshold = 0.5, ...) {
1453+
tidy.catboost_exp <- function(x, type = "importance", pretty.name = FALSE, binary_classification_threshold = 0.5, report_metrics = FALSE, ...) {
14481454
if ("error" %in% class(x) && type != "evaluation") {
14491455
return(data.frame())
14501456
}
@@ -1463,14 +1469,31 @@ tidy.catboost_exp <- function(x, type = "importance", pretty.name = FALSE, binar
14631469
}
14641470
actual <- extract_actual(x)
14651471
if ("catboost_reg" %in% class(x) || identical(x$classification_type, "regression")) {
1466-
ret <- glance(x, pretty.name = pretty.name, ...)
1472+
ret <- glance(x, pretty.name = pretty.name, report_metrics = report_metrics, ...)
14671473
} else if ("catboost_binary" %in% class(x) || identical(x$classification_type, "binary")) {
14681474
predicted <- extract_predicted_binary_labels(x, threshold = binary_classification_threshold)
14691475
predicted_probability <- extract_predicted(x)
1470-
ret <- evaluate_binary_classification(actual, predicted, predicted_probability, pretty.name = pretty.name)
1476+
# Pass report_metrics for Analytics Report Summary ROC AUC / PR AUC (#37256).
1477+
ret <- evaluate_binary_classification(actual, predicted, predicted_probability, pretty.name = pretty.name, report_metrics = report_metrics)
14711478
} else {
14721479
predicted <- extract_predicted_multiclass_labels(x)
14731480
ret <- evaluate_multi_(data.frame(predicted = predicted, actual = actual), "predicted", "actual", pretty.name = pretty.name)
1481+
if (report_metrics) {
1482+
balanced_accuracy <- multiclass_balanced_accuracy(actual, predicted)
1483+
auc_by_class <- multiclass_auc_by_class(actual, tryCatch(extract_predicted(x), error = function(e) NULL))
1484+
macro_roc_auc <- if (nrow(auc_by_class) > 0) mean(auc_by_class$roc_auc, na.rm = TRUE) else NA_real_
1485+
macro_pr_auc <- if (nrow(auc_by_class) > 0) mean(auc_by_class$pr_auc, na.rm = TRUE) else NA_real_
1486+
extra <- if (pretty.name) {
1487+
tibble::tibble(`Balanced Accuracy` = balanced_accuracy,
1488+
`Macro ROC AUC` = macro_roc_auc,
1489+
`Macro PR AUC` = macro_pr_auc)
1490+
} else {
1491+
tibble::tibble(balanced_accuracy = balanced_accuracy,
1492+
macro_roc_auc = macro_roc_auc,
1493+
macro_pr_auc = macro_pr_auc)
1494+
}
1495+
ret <- dplyr::bind_cols(ret, extra)
1496+
}
14741497
}
14751498
if (!is.null(x$inf_removed_rows) && x$inf_removed_rows > 0) {
14761499
ret$Note <- if ("Note" %in% colnames(ret)) paste(ret$Note, x$inf_removed_message, sep = " ") else x$inf_removed_message
@@ -1487,7 +1510,12 @@ tidy.catboost_exp <- function(x, type = "importance", pretty.name = FALSE, binar
14871510
per_level <- function(level) {
14881511
evaluate_classification(actual, predicted, level, pretty.name = pretty.name)
14891512
}
1490-
dplyr::bind_rows(lapply(levels(actual), per_level))
1513+
ret <- dplyr::bind_rows(lapply(levels(actual), per_level))
1514+
if (report_metrics && nrow(ret) > 0) {
1515+
ret <- dplyr::bind_cols(ret, evaluate_by_class_report_metrics(
1516+
actual, predicted, levels(actual), tryCatch(extract_predicted(x), error = function(e) NULL), pretty.name))
1517+
}
1518+
ret
14911519
},
14921520
conf_mat = ,
14931521
confusion_matrix = {

0 commit comments

Comments
 (0)