Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn's KFold function with shuffle and random_state

I'm trying to understand how to use the cross-validation function sklearn.model_selection.KFold. If I define (like in this tutorial)

from sklearn.model_selection import KFold

kf = KFold(n_splits=5, shuffle=False, random_state=100)

I get

ValueError: Setting a random_state has no effect since shuffle is False.
You should leave random_state to its default (None), or set shuffle=True. 

What does this error mean and why is it necessary to set random_state=None or shuffle=True?

like image 518
Medulla Oblongata Avatar asked Nov 05 '25 16:11

Medulla Oblongata


1 Answers

Shuffling in this context means that the data is first randomly shuffled before splitting into test/train. The random_state will allow the way in which the data is shuffled to be repeatable. Without the shuffling switched on, the random_state has no meaning.

like image 72
Taylrl Avatar answered Nov 07 '25 11:11

Taylrl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!