dimanche 6 décembre 2015

What exactly does this random.uniform line in Python do?

I'm following a tutorial here from Andrew Cross on using random forests in Python. I got the code to run fine, and for the most part I understand the output. However, I am unsure on exactly what this line does:

df['is_train'] = np.random.uniform(0, 1, len(df)) <= .75

I know that it "creates a (random) uniform distribution between 0 and 1 and assigns 3/4ths of the data to be in the training subset." However, the training subset is not always exactly 3/4 of the subset. Sometimes it is smaller and sometimes it is larger. So is a random sized subset chosen that is approximately 75%? Why not make it always 75%?




Aucun commentaire:

Enregistrer un commentaire