Curvingo · Made in India

Glossary

Select one of the keywords on the left…

Random ForestCode with Python

Reading time: ~5 min

In scikit-learn a random forest takes the same few lines as a single tree. n_estimators is the number of trees; each tree gets its own bag and its own random features, and random_state=0 makes that randomness repeat exactly every time you run the program. Run it, then pick a different number of trees and run it again.

Bagging by Hand

Python's random.choices draws with replacement, which is exactly a bootstrap bag. random.seed fixes the random numbers, so the same seed always gives the same bag. Run it with two different seeds.

A Forest From Scratch

Here is a whole forest in plain Python. To keep it short, each tree asks just one question about a random feature, and it cuts at the average of its own bag. Five such trees then vote on a new mango of 260 g and 12 cm — long, so a Totapuri. Run it with two different seeds.

Different seeds give different bags, different features and different trees, and a tree or two votes for Alphonso. The majority still gets the mango right.

To reveal more content, you have to complete all the activities and exercises above. 
Are you stuck? or reveal all steps

Next up:
Summary
Sina