Menu
CoddyTech

Recap: Forest Ranger

Part of the Supervised Learning section of Coddy's Machine Learning journey. Lesson 44 of 58.

challenge icon

Challenge

Medium

Race this chapter's two teams of trees. A park ranger wants to know which campsites bears will visit, and what draws them; the starter loads campsites.csv.

  1. Cross-validate a forest of 100 trees and boosting with default settings, cv=5, both random_state=0. Print each mean and std.
  2. Print the winner by mean, and fit it on all the rows.
  3. Draw its importances as sideways bars, smallest first, titled What Brings Bears, x label Importance.

Another park, about raccoons:

Forest: mean 0.780, std 0.086
Boosting: mean 0.787, std 0.075
Winner: boosting

Sideways bars titled What Brings Raccoons, smallest at the bottom: oaks about 0.06, visitors 0.16, bins 0.21, tables 0.24 and creek_m 0.33 on top

Coddy then describes your chart.

Try it yourself

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import cross_val_score
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier

# 200 campsites: distance to a stream, bear-proof food lockers (1 or 0), trash bins,
# altitude, berry bushes nearby, campers a week, and whether a bear visited (1 or 0)
sites = pd.read_csv("campsites.csv")
features = ["stream_m", "lockers", "bins", "altitude_m", "berries", "campers"]

# Write your code below

All lessons in Supervised Learning

Practice on your own: Online Python compiler