C part export a model dump string
This commit is contained in:
parent
3d0bbae2c2
commit
6fd8bbe71a
@ -32,6 +32,8 @@ xgb.dump <- function(model, fname, fmap = "", with.stats=FALSE) {
|
|||||||
if (typeof(fname) != "character") {
|
if (typeof(fname) != "character") {
|
||||||
stop("xgb.dump: second argument must be type character")
|
stop("xgb.dump: second argument must be type character")
|
||||||
}
|
}
|
||||||
.Call("XGBoosterDumpModel_R", model, fname, fmap, as.integer(with.stats), PACKAGE = "xgboost")
|
result <- .Call("XGBoosterDumpModel_R", model, fmap, as.integer(with.stats), PACKAGE = "xgboost")
|
||||||
|
writeLines(result, fname)
|
||||||
|
#unlist(str_split(a, "\n"))==""
|
||||||
return(TRUE)
|
return(TRUE)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -272,20 +272,21 @@ extern "C" {
|
|||||||
XGBoosterSaveModel(R_ExternalPtrAddr(handle), CHAR(asChar(fname)));
|
XGBoosterSaveModel(R_ExternalPtrAddr(handle), CHAR(asChar(fname)));
|
||||||
_WrapperEnd();
|
_WrapperEnd();
|
||||||
}
|
}
|
||||||
void XGBoosterDumpModel_R(SEXP handle, SEXP fname,
|
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats) {
|
||||||
SEXP fmap, SEXP with_stats) {
|
|
||||||
_WrapperBegin();
|
_WrapperBegin();
|
||||||
bst_ulong olen;
|
bst_ulong olen;
|
||||||
const char **res = XGBoosterDumpModel(R_ExternalPtrAddr(handle),
|
const char **res = XGBoosterDumpModel(R_ExternalPtrAddr(handle),
|
||||||
CHAR(asChar(fmap)),
|
CHAR(asChar(fmap)),
|
||||||
asInteger(with_stats),
|
asInteger(with_stats),
|
||||||
&olen);
|
&olen);
|
||||||
FILE *fo = utils::FopenCheck(CHAR(asChar(fname)), "w");
|
SEXP out = PROTECT(allocVector(STRSXP, olen));
|
||||||
for (size_t i = 0; i < olen; ++i) {
|
char buffer [2000];
|
||||||
fprintf(fo, "booster[%u]:\n", static_cast<unsigned>(i));
|
for (size_t i = 0; i < olen; ++i) {
|
||||||
fprintf(fo, "%s", res[i]);
|
sprintf (buffer, "booster[%u]:\n%s", static_cast<unsigned>(i), res[i]);
|
||||||
|
SET_STRING_ELT(out, i, mkChar(buffer));
|
||||||
}
|
}
|
||||||
fclose(fo);
|
|
||||||
_WrapperEnd();
|
_WrapperEnd();
|
||||||
|
UNPROTECT(1);
|
||||||
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,12 +128,11 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
void XGBoosterSaveModel_R(SEXP handle, SEXP fname);
|
void XGBoosterSaveModel_R(SEXP handle, SEXP fname);
|
||||||
/*!
|
/*!
|
||||||
* \brief dump model into text file
|
* \brief dump model into a string
|
||||||
* \param handle handle
|
* \param handle handle
|
||||||
* \param fname file name of model that can be dumped into
|
|
||||||
* \param fmap name to fmap can be empty string
|
* \param fmap name to fmap can be empty string
|
||||||
* \param with_stats whether dump statistics of splits
|
* \param with_stats whether dump statistics of splits
|
||||||
*/
|
*/
|
||||||
void XGBoosterDumpModel_R(SEXP handle, SEXP fname, SEXP fmap, SEXP with_stats);
|
SEXP XGBoosterDumpModel_R(SEXP handle, SEXP fmap, SEXP with_stats);
|
||||||
}
|
}
|
||||||
#endif // XGBOOST_WRAPPER_R_H_
|
#endif // XGBOOST_WRAPPER_R_H_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user