TensorTonic
Problems
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
Streaming Min-Max NormalizationMediumMin-Max Scale Each Feature Column in PythonMediumWinsorize Data by Percentile in PythonMediumMin-Max Normalize Rows or Columns in NumPyEasyLog Transform Features in PythonEasyImplement z-Score StandardizationEasyOne-Hot Encoding (Multi-class)MediumEncode AlphaGo Zero Board HistoryMediumNormalize ColumnsMediumMissing Value ImputationEasyAngle FeaturesEasyFeature ScalingEasy
Scratchpad

Accepts: array

You must run your code first.
Robust Scaling

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
Streaming Min-Max NormalizationMediumMin-Max Scale Each Feature Column in PythonMediumWinsorize Data by Percentile in PythonMediumMin-Max Normalize Rows or Columns in NumPyEasyLog Transform Features in PythonEasyImplement z-Score StandardizationEasyOne-Hot Encoding (Multi-class)MediumEncode AlphaGo Zero Board HistoryMediumNormalize ColumnsMediumMissing Value ImputationEasyAngle FeaturesEasyFeature ScalingEasy
Scratchpad

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1