<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Trees and Forests
Step1:  Decision Tree Classification
Step2:  Random Forests
Step3:  Selecting the Optimal Estimator via Cross-Validation
Step4:  Exercises
Plot the validation curve for the maximum depth of a decision tree on the digits dataset.
Plot the validation curve for max_features of a random forest on the digits dataset.
<ASSISTANT_TASK:>
Python Code:
%matplotlib nbagg
import numpy as np
import matplotlib.pyplot as plt
Explanation: Trees and Forests
End of explanation
from plots import plot_tree_interactive
plot_tree_interactive()
Explanation: Decision Tree Classification
End of explanation
from plots import plot_forest_interactive
plot_forest_interactive()
Explanation: Random Forests
End of explanation
from sklearn import grid_search
from sklearn.datasets import load_digits
from sklearn.cross_validation import train_test_split
from sklearn.ensemble import RandomForestClassifier
digits = load_digits()
X, y = digits.data, digits.target
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
rf = RandomForestClassifier(n_estimators=200, n_jobs=-1)
parameters = {'max_features':['sqrt', 'log2'],
              'max_depth':[5, 7, 9]}
clf_grid = grid_search.GridSearchCV(rf, parameters)
clf_grid.fit(X_train, y_train)
clf_grid.score(X_train, y_train)
clf_grid.score(X_test, y_test)
Explanation: Selecting the Optimal Estimator via Cross-Validation
End of explanation
# %load solutions/forests.py
Explanation: Exercises
Plot the validation curve for the maximum depth of a decision tree on the digits dataset.
Plot the validation curve for max_features of a random forest on the digits dataset.
End of explanation
<END_TASK>