Winsorization limits extreme observations without removing them. Compute lower and upper percentile bounds by linearly interpolating within the sorted values, then clip every original value to those bounds.
For a percentile p and n sorted values, compute its fractional index:
k=100(n−1)pInterpolate between the surrounding sorted entries:
qp=a⌊k⌋+(k−⌊k⌋)(a⌈k⌉−a⌊k⌋)Here, a is the sorted copy of values and q_p is the percentile bound. Clip values below the lower bound upward and values above the upper bound downward. Return the clipped values in their original order.
Input: values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], lower_pct = 10, upper_pct = 90
Output: [1.9, 2, 3, 4, 5, 6, 7, 8, 9, 9.1]
Explanation: The interpolated bounds are 1.9 and 9.1, so only the first and last values are clipped.
Input: values = [1, 2, 3, 4, 5], lower_pct = 0, upper_pct = 100
Output: [1, 2, 3, 4, 5]
Use (len(values) - 1) * percentile / 100 for the fractional sorted index.
Clip each original value with max(lower_bound, min(upper_bound, value)).
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Winsorization limits extreme observations without removing them. Compute lower and upper percentile bounds by linearly interpolating within the sorted values, then clip every original value to those bounds.
For a percentile p and n sorted values, compute its fractional index:
k=100(n−1)pInterpolate between the surrounding sorted entries:
qp=a⌊k⌋+(k−⌊k⌋)(a⌈k⌉−a⌊k⌋)Here, a is the sorted copy of values and q_p is the percentile bound. Clip values below the lower bound upward and values above the upper bound downward. Return the clipped values in their original order.
Input: values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], lower_pct = 10, upper_pct = 90
Output: [1.9, 2, 3, 4, 5, 6, 7, 8, 9, 9.1]
Explanation: The interpolated bounds are 1.9 and 9.1, so only the first and last values are clipped.
Input: values = [1, 2, 3, 4, 5], lower_pct = 0, upper_pct = 100
Output: [1, 2, 3, 4, 5]
Use (len(values) - 1) * percentile / 100 for the fractional sorted index.
Clip each original value with max(lower_bound, min(upper_bound, value)).
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number