How to seed the random number generator for scikit-learn?
<p>I'm trying to write a unit test for some of my code that uses scikit-learn. However, my unit tests seem to be non-deterministic.</p>

<p>AFAIK, the only places in my code where scikit-learn uses any randomness are in its <code>LogisticRegression</code> model and its <code>train_test_split</code>, so I have the following:</p>

<pre><code>RANDOM_SEED = 5
self.lr = LogisticRegression(random_state=RANDOM_SEED)
X_train, X_test, y_train, test_labels = train_test_split(docs, labels, test_size=TEST_SET_PROPORTION, random_state=RANDOM_SEED)
</code></pre>

<p>But this doesn't seem to work -- even when I pass a fixed <code>docs</code> and a fixed <code>labels</code>, the prediction probabilities on a fixed validation set vary from run to run.</p>

<p>I also tried adding a <code>numpy.random.seed(RANDOM_SEED)</code> call at the top of my code, but that didn't seem to work either.</p>

<p>Is there anything I'm missing? Is there a way to pass a seed to scikit-learn in a single place, so that seed is used throughout all of scikit-learn's invocations?</p>