February 2018
Intermediate to advanced
378 pages
10h 14m
English
Let's train trees with different depths: starting from 1 split, and to maximal 23 splits:
In []:
train_losses = []
test_losses = []
for depth in xrange(1, 23):
tree_model.max_depth = depth
tree_model = tree_model.fit(X_train, y_train)
train_losses.append(1 - tree_model.score(X_train, y_train))
test_losses.append(1 - tree_model.score(X_test, y_test))
figure = plt.figure()
plt.plot(train_losses, label="training loss", linestyle='--')
plt.plot(test_losses, label="test loss")
plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)
Out[]:

Read now
Unlock full access