Skip to content

Commit

Permalink
[python] remove verbose argument of model_from_string() method of…
Browse files Browse the repository at this point in the history
… Booster class (#4877)
  • Loading branch information
StrikerRUS authored Dec 11, 2021
1 parent 0e25841 commit 8066261
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions python-package/lightgbm/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ def __init__(self, params=None, train_set=None, model_file=None, model_str=None)
self.__num_class = out_num_class.value
self.pandas_categorical = _load_pandas_categorical(file_name=model_file)
elif model_str is not None:
self.model_from_string(model_str, verbose="_silent_false")
self.model_from_string(model_str)
else:
raise TypeError('Need at least one training dataset or model file or model string '
'to create Booster instance')
Expand Down Expand Up @@ -3300,15 +3300,13 @@ def shuffle_models(self, start_iteration=0, end_iteration=-1):
ctypes.c_int(end_iteration)))
return self

def model_from_string(self, model_str, verbose='warn'):
def model_from_string(self, model_str):
"""Load Booster from a string.
Parameters
----------
model_str : str
Model will be loaded from this string.
verbose : bool, optional (default=True)
Whether to print messages while loading model.
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion python-package/lightgbm/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def train(
for dataset_name, eval_name, score, _ in evaluation_result_list:
booster.best_score[dataset_name][eval_name] = score
if not keep_training_booster:
booster.model_from_string(booster.model_to_string(), verbose='_silent_false').free_dataset()
booster.model_from_string(booster.model_to_string()).free_dataset()
return booster


Expand Down
4 changes: 2 additions & 2 deletions tests/python_package_test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ def test_pandas_categorical():
gbm4 = lgb.Booster(model_file='categorical.model')
pred4 = gbm4.predict(X_test)
model_str = gbm4.model_to_string()
gbm4.model_from_string(model_str, False)
gbm4.model_from_string(model_str)
pred5 = gbm4.predict(X_test)
gbm5 = lgb.Booster(model_str=model_str)
pred6 = gbm5.predict(X_test)
Expand Down Expand Up @@ -2146,7 +2146,7 @@ def test_model_size():
num_end_spaces = 2**31 - one_tree_size * total_trees
new_model_str = f"{before_tree_sizes}\n\n{trees}{more_trees}{after_trees}{'':{num_end_spaces}}"
assert len(new_model_str) > 2**31
bst.model_from_string(new_model_str, verbose=False)
bst.model_from_string(new_model_str)
assert bst.num_trees() == total_trees
y_pred_new = bst.predict(X, num_iteration=2)
np.testing.assert_allclose(y_pred, y_pred_new)
Expand Down

0 comments on commit 8066261

Please sign in to comment.