Explore Library
Code QuizIntermediate

Choosing the Best Threshold

Debug a routine that picks the split threshold with lowest impurity.

Codepython
def best_threshold(thresholds, impurities):
    best_t = None
    best_impurity = float('-inf')
    for t, imp in zip(thresholds, impurities):
        if imp < best_impurity:
            best_impurity = imp
            best_t = t
    return best_t

This should return the threshold with the minimum impurity. What is the bug?