When To Use Random_state=0 - Q&A - Dataquest Community
Maybe your like
We can use random_state to reproduce same output every time. Here, In context of sampling we are using pd.DataFrame.sample that return a random sample of items from data frame. (Without setting random_state Every time it will return different results or sample.)
But if we want to re-produce same output each time say for testing purpose then we take use of random_state.
For example: Using stratum_F from the mission Without random_state
stratum_F = wnba[wnba["Pos"] == "F"] # Without setting `random_state` print(stratum_F.sample(2)) print(stratum_F.sample(2)) Name Team Pos Height Weight BMI Birth_Place ... 55 Evelyn Akhator DAL F 191 82.0 22.477454 NG ... 76 Kayla Pedersen CON F 193 86.0 23.087868 US ... [2 rows x 33 columns] Name Team Pos Height Weight BMI Birth_Place ... 17 Bashaara Graves CHI F 188 91.0 25.746944 US ... 108 Ramu Tokashiki SEA F 193 80.0 21.477087 JP ... [2 rows x 33 columns]First it return [55, 76] rows and second time [17, 108].
With random_state=123 (We can set any integer number to random_state.)
print(stratum_F.sample(2, random_state=123)) print(stratum_F.sample(2, random_state=123)) Name Team Pos Height Weight BMI Birth_Place ... 29 Candice Dupree IND F 188 81.0 22.917610 US ... 103 Nneka Ogwumike LA F 188 79.0 22.351743 US ... [2 rows x 33 columns] Name Team Pos Height Weight BMI Birth_Place ... 29 Candice Dupree IND F 188 81.0 22.917610 US ... 103 Nneka Ogwumike LA F 188 79.0 22.351743 US ... [2 rows x 33 columns]Both time return same [29, 103] rows.
Hope that helps!
@candiceliu93
Tag » What Is Random_state In Python
-
Python Random State In Splitting Dataset - Intellipaat Community
-
Why Do We Set A Random State In Machine Learning Models?
-
Scikit-learn Random State In Splitting Dataset - Python - Stack Overflow
-
Random_state In Machine Learning | Data Science And ... - Kaggle
-
What Is Random_state?. Random State = 0 Or 42 Or None
-
What Is Random State In Machine Learning? - YouTube
-
Set A "random_state" To Make Your Code Reproducible - YouTube
-
del_ain_test_split
-
Why Random_state=42 In Machine Learning? - Thecleverprogrammer
-
Why Random_state In Train_test_split Is Equal 42 - ResearchGate
-
What Is Random State In Machine Learning? | Analytics Vidhya
-
ndom.RandomState — NumPy V1.16 Manual
-
Randomstate - PyPI
-
How Choosing A Value For Random_state Argument In Sklearn ...