3.4.8.2. Measuring Decision Tree performanceΒΆ

Demonstrates overfit when testing on train set.

Get the data

from sklearn.datasets import fetch_california_housing
data = fetch_california_housing(as_frame=True)

Train and test a model

Plot predicted as a function of expected

import matplotlib.pyplot as plt
plt.figure(figsize=(4, 3))
plt.scatter(expected, predicted)
plt.plot([0, 5], [0, 5], "--k")
plt.axis("tight")
plt.xlabel("True price ($100k)")
plt.ylabel("Predicted price ($100k)")
plt.tight_layout()
plot measuring performance

Pretty much no errors!

This is too good to be true: we are testing the model on the train data, which is not a measure of generalization.

The results are not valid

Total running time of the script: (0 minutes 1.899 seconds)

Gallery generated by Sphinx-Gallery