random_state maintained when running script again?
<p>Suppose I have a program, called <code>script.py</code>:</p>

<pre><code>import pandas as pd
import numpy as np
from sklearn.cross_validation import train_test_split

if __name__ == "__main__":
    df = pd.DataFrame({"x": [1,2,3,4,5,6,6,5,6,3], "y": [1,1,0,0,0,0,1,0,0,1]})

    train, test = train_test_split(df, test_size = 0.20, random_state = 100)
</code></pre>

<p>If I run this script from my command line once:</p>

<pre><code>H:\&gt;python script.py
</code></pre>

<p>How can I ensure that the <code>train</code> and <code>test</code> dataframes in subsequent runs (i.e. when I run <code>script.py</code> again) are identical to the <code>train</code> and <code>test</code> dataframes from previous iterations? I know the <code>random_state</code> works if you don't leave the console, but would the equality of these <code>train</code> and <code>test</code> sets be preserved if I came back tomorrow, turned my PC back on, and re-ran <code>script.py</code>?</p>

<p>I am testing the accuracies of different machine learning algorithms, all stored in different scripts, which is why I want to make sure the train and test sets are identical across scripts.  </p>

<p>Random state how nothing to do with when you run your code. The whole concept of specifing random state is to have <strong>exactly the same results every time you run this code with the same parameters</strong>. So as long as you do not change df, test_size and random_state, this function will always return the same values, no matter how many days pass. It might, however, change if you update the underlying library.</p>

python random scikit-learn