Back to questions
JuniorTheoryCommon
What does this program print?
from sklearn.tree import DecisionTreeClassifier
X = [[1], [2], [3], [4], [5], [6]]
y = [0, 0, 1, 0, 1, 1]
deep = DecisionTreeClassifier(random_state=0).fit(X, y)
stump = DecisionTreeClassifier(max_depth=1, random_state=0).fit(X, y)
print(deep.score(X, y), round(stump.score(X, y), 2))1.0 0.83
- Expecting the unlimited tree to miss the lone
0atx = 4: withoutmax_depthit keeps splitting until every leaf is pure, so it scores1.0on its training data. - Expecting
max_depth=1to make no split: depth 1 is one question and two leaves, which gets 5 of the 6 training samples right, so the score is0.83.
- Which of the two trees would you expect to do better on new data, and why?
- How does
min_samples_leaflimit a tree differently frommax_depth?