Decision Trees

Machine Learning for Finance in Python

Nathan George

Data Science Professor

Decision trees

basic decision tree

Machine Learning for Finance in Python

Decision trees

decision tree with targets

Machine Learning for Finance in Python

Decision tree splits

categorical decision tree split

Machine Learning for Finance in Python

Decision tree splits

numerical decision tree split

Machine Learning for Finance in Python

Bad tree

bad regression split

Machine Learning for Finance in Python

Good tree

good regression split

Machine Learning for Finance in Python

Decision tree regression

decision tree predictions

Machine Learning for Finance in Python

Regression trees

from sklearn.tree import DecisionTreeRegressor

decision_tree = DecisionTreeRegressor(max_depth=5)

decision_tree.fit(train_features, train_targets)
Machine Learning for Finance in Python

Decision tree hyperparameters

max depth of trees

Machine Learning for Finance in Python

Max depth of 3

max depth of 3 decision tree

Machine Learning for Finance in Python

Evaluate model

print(decision_tree.score(train_features, train_targets))
print(decision_tree.score(test_features, test_targets))
0.6662215501032416
-0.08917300191734268
train_predictions = decision_tree.predict(train_features)
test_predictions = decision_tree.predict(test_features)
plt.scatter(train_predictions, train_targets, label='train')
plt.scatter(test_predictions, test_targets, label='test')
plt.legend()
plt.show()
Machine Learning for Finance in Python

predictions vs actual

Machine Learning for Finance in Python

Grow some trees!

Machine Learning for Finance in Python

Preparing Video For Download...