Why choose random_state ?

Some scikit-learn objects are inherently random. The random_state is used to control the randomness of these scikit-learn objects. The random_state can be an integer, nonNumPynumpy.random.RandomState(seed=None). The random_state parameter will be the predetermined criteria to select the sample from the entire population(dataset). Here all the members of the population have an equal probability to get selected, as a result, the sample will be unbiased. More about sampling can be read here.
The random_state or seed when set to an integer parameter, the result produced will be the same irrespective of how many times we have executed the code with the same dataset on the same machine or a different machine, or by a different user. In short, we can say it is a way of recreating the same result so that if there is a need to debug the code, we can recreate the same result. Whereas when random_state is set to none, or Numpy.random.RandomState(seed=one) , a random_state or pseudo-random number will be generated internally and the result for each run will be different from the previous one or rather we can say it is unpredictable.
Usually, random_state is used in:
- Machine learning for train_test_split() function, to split the dataset into training and test sets.
- Data quality, for sample() function, to select random data from the dataset to analyze it for the data quality checks.
When the random_state or seed is set to an integer the pseudo-random number generated will be the same irrespective of the number of times the function is called, thus the result produced will be the same all the time. The most popular random seed is 42 and it can range from [0, 2**32–1], both inclusive. The reason for 42 being the most popular is because in The Hitchhiker’s Guide to the Galaxy by Douglas Adams, the “Answer to the Ultimate Question of Life, the Universe, and Everything,” calculated by an enormous supercomputer named Deep Thought over a period of 7.5 million years. Moreover, the 42 number has great importance in Mathematics, Science, Technology, Astronomy, Religion, and other cultures. But as per scikit-learn any integer used between [0, 2**32–1] to generate a pseduo-random number has equal or same weightage.