Skip to content

Commit b6a8394

Browse files
committed
Clone RPF object
1 parent 442affb commit b6a8394

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

R/convert_xgboost.R

+23
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,26 @@ convert_xgboost_rpf <- function(xg, x, y) {
7474
# Return manipulated rpf object
7575
rpfit
7676
}
77+
78+
79+
#' Clone rpf object
80+
#'
81+
#' @param to_clone rpf object
82+
#' @param x data used to train the xgboost model
83+
#' @param y target used to train the xgboost model
84+
#'
85+
#' @return rpf object
86+
#' @export
87+
clone <- function(to_clone, x, y) {
88+
# create a dummy rpf
89+
rpfit <- rpf(x = x, y = y, max_interaction = 0, ntrees = to_clone$params$ntrees, splits = 1,
90+
purify = FALSE, loss = to_clone$params$loss)
91+
92+
subsetted <- to_clone$params[names(to_clone$params) != "loss"]
93+
rpfit$fit$set_parameters(names(subsetted), unlist(subsetted))
94+
# Also overwrite C++ forest
95+
rpfit$fit$set_model(to_clone$forest)
96+
97+
# Return manipulated rpf object
98+
rpfit
99+
}

0 commit comments

Comments
 (0)