Skip to content
ml-recall

#cart

1 question from Decision Trees & Ensembles

Timed test

1 question · 1 min · score and explanations at the end

Take a test
Q 1 / 1Score 0 / 0

Question 1: Short answer

hardAI-checkedDecision Trees & Ensembles
from sklearn.tree import DecisionTreeClassifier

X = [[0], [1], [2], [3], [4]]
y = ["A", "B", "A", "A", "A"]
tree = DecisionTreeClassifier(max_depth=1, random_state=0).fit(X, y)

print(tree.tree_.threshold[0])          # split threshold of the root
print(tree.tree_.impurity.round(2))     # Gini impurity: [root, left child, right child]

The first line prints . The second line prints [0.32 ... 0.], where the left child's impurity, hidden here, is .

Fill in every blank (hints in the boxes). Enter moves to the next blank.