Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ jobs:
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true
# P3M's macOS binaries are built with OpenMP enabled, but the runners
# have no libomp, so e.g. gower fails to load. CRAN's own macOS
# binaries are built without it, so use those instead.
use-public-rspm: ${{ matrix.config.os != 'macos-latest' }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
Expand Down
208 changes: 208 additions & 0 deletions tests/testthat/_snaps/3.2.1.1/discretize_xgb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
# run_xgboost for classification

Code
xgboost
Output
##### xgb.Booster
call:
xgboost::xgb.train(params = .params, data = .train, nrounds = 100,
evals = list(train = .train, test = .test), verbose = 0,
early_stopping_rounds = 10)
# of features: 13
# of rounds: 80
xgb.attributes:
best_iteration, best_score
callbacks:
early_stop, evaluation_log
evaluation_log:
iter train_logloss test_logloss
<num> <num> <num>
1 0.5739956 0.5763535
2 0.5546428 0.5563444
--- --- ---
79 0.4189363 0.4445886
80 0.4186880 0.4440128

# run_xgboost for multi-classification

Code
xgboost
Output
##### xgb.Booster
call:
xgboost::xgb.train(params = .params, data = .train, nrounds = 100,
evals = list(train = .train, test = .test), verbose = 0,
early_stopping_rounds = 10)
# of features: 30
# of rounds: 31
xgb.attributes:
best_iteration, best_score
callbacks:
early_stop, evaluation_log
evaluation_log:
iter train_mlogloss test_mlogloss
<num> <num> <num>
1 1.363338 1.377775
2 1.331378 1.352738
--- --- ---
30 1.160942 1.255252
31 1.159259 1.256760

# run_xgboost for regression

Code
xgboost
Output
##### xgb.Booster
call:
xgboost::xgb.train(params = .params, data = .train, nrounds = 100,
evals = list(train = .train, test = .test), verbose = 0,
early_stopping_rounds = 10)
# of features: 73
# of rounds: 25
xgb.attributes:
best_iteration, best_score
callbacks:
early_stop, evaluation_log
evaluation_log:
iter train_rmse test_rmse
<num> <num> <num>
1 0.15708398 0.1633305
2 0.14190657 0.1588983
--- --- ---
24 0.07039493 0.1211529
25 0.06975907 0.1206107

# xgb_binning for classification

Code
xgb_binning
Output
[1] 1 2 3 5 6 9 12 15 20

# xgb_binning for multi-classification

Code
xgb_binning
Output
[1] 26

# xgb_binning for regression

Code
xgb_binning
Output
[1] 42.01972 42.02510 42.03122 42.03462 42.03840 42.04638 42.05236 42.05917

# step_discretize_xgb for classification

Code
xgb_train_bins[1:10, ]
Output
# A tibble: 10 x 3
x z class
<fct> <fct> <fct>
1 [0.6808, Inf] [0.3327, Inf] a
2 [0.5749,0.6808) [0.3327, Inf] b
3 [0.3687,0.5749) [-Inf,0.3327) b
4 [0.5749,0.6808) [0.3327, Inf] b
5 [0.6808, Inf] [0.3327, Inf] a
6 [0.5749,0.6808) [0.3327, Inf] a
7 [0.5749,0.6808) [-Inf,0.3327) b
8 [0.5749,0.6808) [-Inf,0.3327) a
9 [0.2779,0.3687) [0.3327, Inf] a
10 [0.3687,0.5749) [0.3327, Inf] b

---

Code
xgb_test_bins[1:10, ]
Output
# A tibble: 10 x 3
x z class
<fct> <fct> <fct>
1 [0.5749,0.6808) [-Inf,0.3327) b
2 [0.5749,0.6808) [0.3327, Inf] b
3 [0.3687,0.5749) [-Inf,0.3327) b
4 [0.2779,0.3687) [0.3327, Inf] b
5 [0.6808, Inf] [0.3327, Inf] a
6 [0.3687,0.5749) [-Inf,0.3327) b
7 [0.2779,0.3687) [0.3327, Inf] a
8 [0.6808, Inf] [0.3327, Inf] a
9 [0.3687,0.5749) [0.3327, Inf] b
10 [0.3687,0.5749) [0.3327, Inf] b

---

Code
prep(step_discretize_xgb(recipe(class ~ ., data = sim_tr_cls[1:9, ]),
all_predictors(), outcome = "class"))
Condition
Error in `step_discretize_xgb()`:
Caused by error in `prep()`:
! Too few observations in the early stopping validation set.
i Consider increasing the `sample_val` parameter.

---

Code
set.seed(1)
prep(step_discretize_xgb(recipe(Status ~ ., data = credit_data_train), Time,
outcome = "Status"), retain = TRUE)
Condition
Warning:
More than 20 unique training set values are required.
i Predictors 'Time' were not processed; their original values will be used.
Message

-- Recipe ----------------------------------------------------------------------

-- Inputs
Number of variables by role
outcome: 1
predictor: 13

-- Training information
Training data contained 3340 data points and 301 incomplete rows.

-- Operations
* Discretizing variables using xgboost: <none> | Trained

# step_discretize_xgb for multi-classification

Code
xgb_train_bins[1:10, ]
Output
# A tibble: 10 x 3
x z class
<fct> <fct> <fct>
1 [0.6879, Inf] [0.09924, Inf] c
2 [0.5863,0.6879) [0.09924, Inf] b
3 [0.3821,0.5863) [-Inf,0.09924) b
4 [0.5863,0.6879) [0.09924, Inf] b
5 [0.6879, Inf] [0.09924, Inf] c
6 [0.5863,0.6879) [0.09924, Inf] c
7 [0.5863,0.6879) [-Inf,0.09924) b
8 [0.5863,0.6879) [0.09924, Inf] c
9 [-Inf,0.2887) [0.09924, Inf] a
10 [0.3821,0.5863) [0.09924, Inf] b

---

Code
xgb_test_bins[1:10, ]
Output
# A tibble: 10 x 3
x z class
<fct> <fct> <fct>
1 [0.5863,0.6879) [0.09924, Inf] b
2 [0.5863,0.6879) [0.09924, Inf] b
3 [0.3821,0.5863) [0.09924, Inf] b
4 [0.2887,0.3821) [0.09924, Inf] b
5 [0.6879, Inf] [0.09924, Inf] c
6 [0.3821,0.5863) [-Inf,0.09924) b
7 [0.2887,0.3821) [0.09924, Inf] a
8 [0.6879, Inf] [0.09924, Inf] c
9 [0.3821,0.5863) [0.09924, Inf] b
10 [0.3821,0.5863) [0.09924, Inf] b

Loading