TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Robust Scaling

Feature EngineeringData Processing
Medium

Robust scaling centers values by their median and scales them by the interquartile range. These statistics are less sensitive to extreme values than the mean and standard deviation.

xscaled=x−Q2Q3−Q1x_{\mathrm{scaled}} = \frac{x - Q_2}{Q_3 - Q_1}xscaled​=Q3​−Q1​x−Q2​​

Here, Q_2 is the median, Q_1 is the median of the lower half, and Q_3 is the median of the upper half. Exclude the overall median from both halves when the input length is odd. If the interquartile range is zero, return each value minus the median without division.

Loading visualization...

Examples

Input: values = [1, 2, 3, 4, 5]

Output: [-0.6667, -0.3333, 0.0, 0.3333, 0.6667]

Explanation: The median is 3, the lower and upper quartiles are 1.5 and 4.5, and the interquartile range is 3.

Input: values = [10, 20, 30, 40]

Output: [-0.75, -0.25, 0.25, 0.75]

Hint 1

Write a small helper that returns the median of an already sorted list.

Hint 2

Form the lower and upper halves before computing their medians.

Requirements

  • Compute the median from the sorted values.
  • Compute the lower and upper quartiles from their respective halves.
  • Exclude the overall median from both halves for an odd input length.
  • Use median-centered values without division when the interquartile range is zero.
  • Return results in the original value order.

Constraints

  • values is a nonempty list of numbers.
  • Values may be negative or repeated.
  • Time limit: 300 ms.
Try Similar Problems
Zscore StandardizationMin Max ScalingMinmax NormalizationWinsorizationStreaming Minmax

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.
PrevNext

Robust Scaling

Feature EngineeringData Processing
Medium

Robust scaling centers values by their median and scales them by the interquartile range. These statistics are less sensitive to extreme values than the mean and standard deviation.

xscaled=x−Q2Q3−Q1x_{\mathrm{scaled}} = \frac{x - Q_2}{Q_3 - Q_1}xscaled​=Q3​−Q1​x−Q2​​

Here, Q_2 is the median, Q_1 is the median of the lower half, and Q_3 is the median of the upper half. Exclude the overall median from both halves when the input length is odd. If the interquartile range is zero, return each value minus the median without division.

Loading visualization...

Examples

Input: values = [1, 2, 3, 4, 5]

Output: [-0.6667, -0.3333, 0.0, 0.3333, 0.6667]

Explanation: The median is 3, the lower and upper quartiles are 1.5 and 4.5, and the interquartile range is 3.

Input: values = [10, 20, 30, 40]

Output: [-0.75, -0.25, 0.25, 0.75]

Hint 1

Write a small helper that returns the median of an already sorted list.

Hint 2

Form the lower and upper halves before computing their medians.

Requirements

  • Compute the median from the sorted values.
  • Compute the lower and upper quartiles from their respective halves.
  • Exclude the overall median from both halves for an odd input length.
  • Use median-centered values without division when the interquartile range is zero.
  • Return results in the original value order.

Constraints

  • values is a nonempty list of numbers.
  • Values may be negative or repeated.
  • Time limit: 300 ms.
Try Similar Problems
Zscore StandardizationMin Max ScalingMinmax NormalizationWinsorizationStreaming Minmax

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

You must run your code first.