Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-106

Decision Stump Predict

Problem

Predict with a one-level decision stump. For each value in X, return left_label when x <= threshold and right_label otherwise.

Empty X returns [].

Hint

Compare each value to the threshold and emit the matching label.

Test cases

case 1
in: [[1,2,3,4],2.5,"A","B"]
expected: ["A","A","B","B"]
case 2
in: [[0,0.5,1],0.5,0,1]
expected: [0,0,1]
case 3
in: [[5],5,"yes","no"]
expected: ["yes"]
case 4
in: [[],1,0,1]
expected: []
Starter codePython
def decision_stump_predict(X, threshold, left_label, right_label):
    # Your code here
    pass

4 test cases · run your code against them in the editor