Question: Part Four: Implement evaltree [ Graded ] Implement the function evaltree, which evaluates a decision tree on a given test data set. You essentially need

Part Four: Implement evaltree [Graded]
Implement the function evaltree, which evaluates a decision tree on a given test data set. You essentially need to traverse the tree until you end up in a leaf, where you return the prediction value of the leaf. Like the cart function, you can call evaltree on the left subtree and right subtree on testing points that fall in the corresponding subtrees.
Here's some inspiration:
If the tree is a leaf, i.e. the left and right subtrees are None, return tree.prediction for all m testing points.
If the tree is non-leaf, using tree.feature and tree.cut find testing points with the feature value less than/equal to the threshold and greater than. Now, you can call evaltree on tree.left and the left set of testing points to obtain the left set's predictions. Then obtain the predictions for the right set, and return all predictions.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!