Random ForestCode with Python
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.