Feature Scaling

Hard
feature-engineering

Implement two common feature scaling methods:

  1. Min-Max Scaling: scales each value to [0, 1] using (x - min) / (max - min).
  2. Z-Score Scaling (standardisation): transforms to zero mean and unit variance using (x - mean) / std, where std is the population standard deviation.

Return results rounded to 4 decimal places. If all values are the same (std or range is 0), return a list of 0.0.

Example:

Input:  [1, 2, 3, 4, 5]
min_max_scale → [0.0, 0.25, 0.5, 0.75, 1.0]
z_score_scale → [-1.4142, -0.7071, 0.0, 0.7071, 1.4142]

Test Cases

Python Editor

Output

Click "Run" to see results...