All problems
Sen Slope Trend
Problem
Compute the Sen (Theil-Sen) slope as the median of all pairwise slopes (series[j] - series[i]) / (j - i) for i < j.
Return 0.0 when fewer than two points are available. For an even number of slopes, average the two middle values.
Hint
The median makes the estimator robust to a few outliers.
Test cases
case 1
in: [[1,2,3,4]]
expected: 1
case 2
in: [[1,3,2,4]]
expected: 0.75
case 3
in: [[5,5,5]]
expected: 0
case 4
in: [[10,9,8]]
expected: -1
Starter codePython
def sen_slope(series):
# Your code here
pass4 test cases · run your code against them in the editor