Skip to content

Commit

Permalink
[Python-package]: Fix RandomState issue microsoft#376 (microsoft#377)
Browse files Browse the repository at this point in the history
* Python: Fix RandomState issue microsoft#376

* Add test case for Python's Shuffle=True
  • Loading branch information
Laurae2 authored and guolinke committed Apr 2, 2017
1 parent 945bc15 commit 21861cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python-package/lightgbm/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _make_n_folds(full_data, data_splitter, nfold, params, seed, fpreproc=None,
folds = sfk.split(X=np.zeros(num_data), y=full_data.get_label())
else:
if shuffle:
randidx = np.RandomState(seed).random.permutation(num_data)
randidx = np.random.RandomState(seed).permutation(num_data)
else:
randidx = np.arange(num_data)
kstep = int(num_data / nfold)
Expand Down
3 changes: 3 additions & 0 deletions tests/python_package_test/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def test_cv(self):
lgb.cv({'verbose': -1}, lgb_train, num_boost_round=20, nfold=5, shuffle=False,
metrics='l1', verbose_eval=False,
callbacks=[lgb.reset_parameter(learning_rate=lambda i: 0.1 - 0.001 * i)])
lgb.cv({'verbose': -1}, lgb_train, num_boost_round=20, nfold=5, shuffle=True,
metrics='l1', verbose_eval=False,
callbacks=[lgb.reset_parameter(learning_rate=lambda i: 0.1 - 0.001 * i)])
tss = TimeSeriesSplit(3)
lgb.cv({'verbose': -1}, lgb_train, num_boost_round=20, data_splitter=tss, nfold=5, # test if wrong nfold is ignored
metrics='l2', verbose_eval=False)
Expand Down

0 comments on commit 21861cd

Please sign in to comment.