Skip to content

Commit

Permalink
Merge branch 'master' into read_write_locks
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM authored Jul 16, 2020
2 parents 78d2fc6 + fc79b36 commit 0f3cb8b
Show file tree
Hide file tree
Showing 19 changed files with 482 additions and 62 deletions.
11 changes: 10 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
# catch-all rule (this only gets matched if no rules below match)
* @guolinke @StrikerRUS @jameslamb @Laurae2

# other catch-alls that will get matched if specific rules below are not matched
*.R @Laurae2 @jameslamb
*.py @StrikerRUS @chivee @wxchan @henry0312
*.cpp @guolinke @chivee @btrotta
*.h @guolinke @chivee @btrotta

# main C++ code
include/ @guolinke @chivee @btrotta
src/ @guolinke @chivee @btrotta
CMakeLists.txt @guolinke @chivee @Laurae2 @jameslamb @wxchan @henry0312 @StrikerRUS @huanzhang12 @btrotta
tests/c_api_test/ @guolinke @chivee @btrotta
tests/cpp_test/ @guolinke @chivee @btrotta
tests/data/ @guolinke @chivee @btrotta
windows/ @guolinke @chivee @btrotta @StrikerRUS

# R code
R-package/ @Laurae2 @jameslamb
*.R @Laurae2 @jameslamb

# Python code
python-package/ @StrikerRUS @chivee @wxchan @henry0312
Expand Down
9 changes: 6 additions & 3 deletions R-package/R/lgb.Booster.R
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ Booster <- R6::R6Class(
},

# Save model
save_model = function(filename, num_iteration = NULL) {
save_model = function(filename, num_iteration = NULL, feature_importance_type = 0L) {

# Check if number of iteration is non existent
if (is.null(num_iteration)) {
Expand All @@ -437,6 +437,7 @@ Booster <- R6::R6Class(
, ret = NULL
, private$handle
, as.integer(num_iteration)
, as.integer(feature_importance_type)
, lgb.c_str(filename)
)

Expand All @@ -445,7 +446,7 @@ Booster <- R6::R6Class(
},

# Save model to string
save_model_to_string = function(num_iteration = NULL) {
save_model_to_string = function(num_iteration = NULL, feature_importance_type = 0L) {

# Check if number of iteration is non existent
if (is.null(num_iteration)) {
Expand All @@ -457,12 +458,13 @@ Booster <- R6::R6Class(
"LGBM_BoosterSaveModelToString_R"
, private$handle
, as.integer(num_iteration)
, as.integer(feature_importance_type)
))

},

# Dump model in memory
dump_model = function(num_iteration = NULL) {
dump_model = function(num_iteration = NULL, feature_importance_type = 0L) {

# Check if number of iteration is non existent
if (is.null(num_iteration)) {
Expand All @@ -474,6 +476,7 @@ Booster <- R6::R6Class(
"LGBM_BoosterDumpModel_R"
, private$handle
, as.integer(num_iteration)
, as.integer(feature_importance_type)
)

},
Expand Down
15 changes: 9 additions & 6 deletions R-package/src/lightgbm_R.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,37 +632,40 @@ LGBM_SE LGBM_BoosterPredictForMat_R(LGBM_SE handle,

LGBM_SE LGBM_BoosterSaveModel_R(LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE filename,
LGBM_SE call_state) {
R_API_BEGIN();
CHECK_CALL(LGBM_BoosterSaveModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_CHAR_PTR(filename)));
CHECK_CALL(LGBM_BoosterSaveModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_AS_INT(feature_importance_type), R_CHAR_PTR(filename)));
R_API_END();
}

LGBM_SE LGBM_BoosterSaveModelToString_R(LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE buffer_len,
LGBM_SE actual_len,
LGBM_SE out_str,
LGBM_SE call_state) {
R_API_BEGIN();
int64_t out_len = 0;
std::vector<char> inner_char_buf(R_AS_INT(buffer_len));
CHECK_CALL(LGBM_BoosterSaveModelToString(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_AS_INT(buffer_len), &out_len, inner_char_buf.data()));
CHECK_CALL(LGBM_BoosterSaveModelToString(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_AS_INT(feature_importance_type), R_AS_INT(buffer_len), &out_len, inner_char_buf.data()));
EncodeChar(out_str, inner_char_buf.data(), buffer_len, actual_len, static_cast<size_t>(out_len));
R_API_END();
}

LGBM_SE LGBM_BoosterDumpModel_R(LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE buffer_len,
LGBM_SE actual_len,
LGBM_SE out_str,
LGBM_SE call_state) {
R_API_BEGIN();
int64_t out_len = 0;
std::vector<char> inner_char_buf(R_AS_INT(buffer_len));
CHECK_CALL(LGBM_BoosterDumpModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_AS_INT(buffer_len), &out_len, inner_char_buf.data()));
CHECK_CALL(LGBM_BoosterDumpModel(R_GET_PTR(handle), 0, R_AS_INT(num_iteration), R_AS_INT(feature_importance_type), R_AS_INT(buffer_len), &out_len, inner_char_buf.data()));
EncodeChar(out_str, inner_char_buf.data(), buffer_len, actual_len, static_cast<size_t>(out_len));
R_API_END();
}
Expand Down Expand Up @@ -707,9 +710,9 @@ static const R_CallMethodDef CallEntries[] = {
{"LGBM_BoosterCalcNumPredict_R" , (DL_FUNC) &LGBM_BoosterCalcNumPredict_R , 8},
{"LGBM_BoosterPredictForCSC_R" , (DL_FUNC) &LGBM_BoosterPredictForCSC_R , 14},
{"LGBM_BoosterPredictForMat_R" , (DL_FUNC) &LGBM_BoosterPredictForMat_R , 11},
{"LGBM_BoosterSaveModel_R" , (DL_FUNC) &LGBM_BoosterSaveModel_R , 4},
{"LGBM_BoosterSaveModelToString_R" , (DL_FUNC) &LGBM_BoosterSaveModelToString_R , 6},
{"LGBM_BoosterDumpModel_R" , (DL_FUNC) &LGBM_BoosterDumpModel_R , 6},
{"LGBM_BoosterSaveModel_R" , (DL_FUNC) &LGBM_BoosterSaveModel_R , 5},
{"LGBM_BoosterSaveModelToString_R" , (DL_FUNC) &LGBM_BoosterSaveModelToString_R , 7},
{"LGBM_BoosterDumpModel_R" , (DL_FUNC) &LGBM_BoosterDumpModel_R , 7},
{NULL, NULL, 0}
};

Expand Down
3 changes: 3 additions & 0 deletions R-package/src/lightgbm_R.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterPredictForMat_R(
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R(
LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE filename,
LGBM_SE call_state
);
Expand All @@ -604,6 +605,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModel_R(
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R(
LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE buffer_len,
LGBM_SE actual_len,
LGBM_SE out_str,
Expand All @@ -620,6 +622,7 @@ LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterSaveModelToString_R(
LIGHTGBM_C_EXPORT LGBM_SE LGBM_BoosterDumpModel_R(
LGBM_SE handle,
LGBM_SE num_iteration,
LGBM_SE feature_importance_type,
LGBM_SE buffer_len,
LGBM_SE actual_len,
LGBM_SE out_str,
Expand Down
8 changes: 8 additions & 0 deletions docs/Parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ Learning Control Parameters

- **Note**: can be used only in CLI version

- ``saved_feature_importance_type`` :raw-html:`<a id="saved_feature_importance_type" title="Permalink to this parameter" href="#saved_feature_importance_type">&#x1F517;&#xFE0E;</a>`, default = ``0``, type = int

- the feature importance type in the saved model file

- ``0``: count-based feature importance (numbers of splits are counted); ``1``: gain-based feature importance (values of gain are counted)

- **Note**: can be used only in CLI version

- ``snapshot_freq`` :raw-html:`<a id="snapshot_freq" title="Permalink to this parameter" href="#snapshot_freq">&#x1F517;&#xFE0E;</a>`, default = ``-1``, type = int, aliases: ``save_period``

- frequency of saving model file snapshot
Expand Down
10 changes: 6 additions & 4 deletions include/LightGBM/boosting.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,10 @@ class LIGHTGBM_EXPORT Boosting {
* \brief Dump model to json format string
* \param start_iteration The model will be saved start from
* \param num_iteration Number of iterations that want to dump, -1 means dump all
* \param feature_importance_type Type of feature importance, 0: split, 1: gain
* \return Json format string of model
*/
virtual std::string DumpModel(int start_iteration, int num_iteration) const = 0;
virtual std::string DumpModel(int start_iteration, int num_iteration, int feature_importance_type) const = 0;

/*!
* \brief Translate model to if-else statement
Expand All @@ -199,19 +200,20 @@ class LIGHTGBM_EXPORT Boosting {
* \brief Save model to file
* \param start_iteration The model will be saved start from
* \param num_iterations Number of model that want to save, -1 means save all
* \param is_finish Is training finished or not
* \param feature_importance_type Type of feature importance, 0: split, 1: gain
* \param filename Filename that want to save to
* \return true if succeeded
*/
virtual bool SaveModelToFile(int start_iteration, int num_iterations, const char* filename) const = 0;
virtual bool SaveModelToFile(int start_iteration, int num_iterations, int feature_importance_type, const char* filename) const = 0;

/*!
* \brief Save model to string
* \param start_iteration The model will be saved start from
* \param num_iterations Number of model that want to save, -1 means save all
* \param feature_importance_type Type of feature importance, 0: split, 1: gain
* \return Non-empty string if succeeded
*/
virtual std::string SaveModelToString(int start_iteration, int num_iterations) const = 0;
virtual std::string SaveModelToString(int start_iteration, int num_iterations, int feature_importance_type) const = 0;

/*!
* \brief Restore from a serialized string
Expand Down
Loading

0 comments on commit 0f3cb8b

Please sign in to comment.