-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d86c418
commit 528c1be
Showing
10 changed files
with
110 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#' Load serialised xgboost model from R's raw vector | ||
#' | ||
#' User can generate raw memory buffer by calling xgb.save.raw | ||
#' | ||
#' @param buffer the buffer returned by xgb.save.raw | ||
#' | ||
#' @export | ||
xgb.load.raw <- function(buffer) { | ||
cachelist <- list() | ||
handle <- .Call(XGBoosterCreate_R, cachelist) | ||
modellst <- unserialize(buffer) | ||
.Call(XGBoosterLoadModelFromRaw_R, handle, modellst$model) | ||
.Call(XGBoosterLoadJsonConfig_R, handle, modellst$config) | ||
class(handle) <- "xgb.Booster.handle" | ||
return (handle) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
#' Save xgboost model to R's raw vector, | ||
#' user can call xgb.load to load the model back from raw vector | ||
#' | ||
#' user can call xgb.load.raw to load the model back from raw vector | ||
#' | ||
#' Save xgboost model from xgboost or xgb.train | ||
#' | ||
#' | ||
#' @param model the model object. | ||
#' | ||
#' | ||
#' @examples | ||
#' data(agaricus.train, package='xgboost') | ||
#' data(agaricus.test, package='xgboost') | ||
#' train <- agaricus.train | ||
#' test <- agaricus.test | ||
#' bst <- xgboost(data = train$data, label = train$label, max_depth = 2, | ||
#' bst <- xgboost(data = train$data, label = train$label, max_depth = 2, | ||
#' eta = 1, nthread = 2, nrounds = 2,objective = "binary:logistic") | ||
#' raw <- xgb.save.raw(bst) | ||
#' bst <- xgb.load(raw) | ||
#' bst <- xgb.load.raw(raw) | ||
#' pred <- predict(bst, test$data) | ||
#' | ||
#' @export | ||
xgb.save.raw <- function(model) { | ||
model <- xgb.get.handle(model) | ||
.Call(XGBoosterModelToRaw_R, model) | ||
handle <- xgb.get.handle(model) | ||
model <- .Call(XGBoosterModelToRaw_R, handle) | ||
config <- .Call(XGBoosterSaveJsonConfig_R, handle) | ||
serialize(list(model=model, config=config), NULL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters