Recap: Forest Ranger
Part of the Supervised Learning section of Coddy's Machine Learning journey. Lesson 44 of 58.
Challenge
MediumRace 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.
- Cross-validate a forest of 100 trees and boosting with default settings,
cv=5, bothrandom_state=0. Print each mean and std. - Print the winner by mean, and fit it on all the rows.
- Draw its importances as sideways bars, smallest first, titled
What Brings Bears, x labelImportance.
Another park, about raccoons:
Forest: mean 0.780, std 0.086
Boosting: mean 0.787, std 0.075
Winner: boostingCoddy 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
1Your First Model
Learning from ExamplesTrain and Test SetsFit and PredictScoring a ModelRecap: Seed Sorter2Nearest Neighbors
How k-NN DecidesChoosing kDecision BoundariesScaling for NeighborsRecap: Wine Neighbors5Measuring Classifiers
The Confusion MatrixPrecision and RecallThe F1 ScoreImbalanced ClassesROC CurvesRecap: Screening Test11Project: Penguin Species
Meet the PenguinsPrepare the DataChoose a ModelTune the WinnerShip the ModelPractice on your own: Online Python compiler