Zomato-inspired ranking filter uses a single numeric feature to separate likely outcomes from unlikely ones. You need to find the threshold that gives the best classification score, providing a simple baseline before the team deploys a larger model. The threshold is the midpoint between two consecutive distinct sorted feature values that minimizes the sample-weighted Gini impurity of the two resulting sides, where the positive class is label 1. Ties go to the smaller threshold. Fewer than two distinct values raises ValueError.
Return the split threshold of a one-feature decision stump. Candidates are the midpoints between consecutive distinct sorted feature values; the winner minimises the sample-weighted Gini impurity of the two sides, and ties go to the smaller threshold.
Implement solve(x, y).
Returns. Return the threshold as a Python float. At least two distinct feature values are required, otherwise ValueError is raised. Labels are 0/1.
Example 1
Input:
solve([1.0, 2.0, 4.0, 7.0], [0, 0, 1, 1])
Output:
3.0
Example 2
Input:
solve([1.0, 2.0, 3.0, 4.0], [0, 1, 0, 1])
Output:
1.5
Example 3
Input:
solve([2.0, 2.0], [0, 1])
Output: Raises ValueError.
No results yet
Run your code to check it against the examples, or submit to run every test.