All problems
Feature Importance Rank Stability
Problem
Measure feature importance rank stability with Spearman's correlation. Convert both importance vectors to average ranks so ties share the mean rank, then return the Pearson correlation of the two rank vectors using population statistics. Return 0.0 for empty input, unequal lengths, or a constant vector.
Hint
Rank correlation tracks whether two explanations agree on ordering, even if scores are not comparable.
Test cases
case 1
in: [[0.1,0.5,0.3],[0.2,0.9,0.4]]
expected: 1
case 2
in: [[1,2,3],[3,2,1]]
expected: -1
case 3
in: [[1,1,2],[3,1,2]]
expected: 0
case 4
in: [[5],[5]]
expected: 0
case 5
in: [[],[]]
expected: 0
Starter codePython
def importance_rank_stability(importance_a, importance_b):
# Your code here
pass5 test cases · run your code against them in the editor