🌍 Become a marimo ambassador!

Apply
99 / 103
PrettyForest

PrettyForest

by Fabio Scantamburlo

Explore tree-based ML ensembles as an interactive 2.5D isometric forest — trace predictions, drill into trees, sort by purity.

About this notebook

This notebook shows tree ensembles from scikit-learn with the prettyforest library. It trains a Random Forest classifier on the Iris dataset. The notebook uses marimo, scikit-learn, and polars. It splits the Iris data into train and test sets. Then it reports the test accuracy in a markdown cell. The prettygrow function from prettyforest renders each fitted model as HTML.

The reader sees a visual grid of the trees in the forest. The markdown text invites the reader to trace a sample, double-click a tree, and sort by purity. A second model, a Gradient Boosting classifier, uses the same test data. For that model a double-click may show a warning. The boosted model also shows gradient correction badges instead of class votes.

The Random Forest uses 100 estimators and a maximum depth of 5. The Gradient Boosting model uses 10 estimators and a maximum depth of 3. Both models use a fixed random_state of 42. The test data becomes a polars DataFrame before prettygrow reads it. The prettygrow function receives the model, the data, and the target labels.

Related notebooks