All problems
Monotonic Violation Count
Problem
Count monotonicity violations: after sorting by feature value, count adjacent pairs where the prediction decreases.
Hint
Each violation is a local decrease as the feature increases.
Test cases
case 1
in: [[1,2,3],[1,3,2]]
expected: 1
case 2
in: [[1,2,3],[3,2,1]]
expected: 2
case 3
in: [[1,2,3],[1,2,3]]
expected: 0
Starter codePython
def monotonic_violation_count(feature_values, predictions):
# Your code here
pass3 test cases · run your code against them in the editor