Question 1: Short answer
hardAI-checkedDecision Trees & Ensemblesfrom 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.