Min-Max Normalization Practice Problem
This data science coding problem helps you practice Mathematical & Statistical Operations, min-max normalization, and implementation skills. Read the problem statement, write your solution, and strengthen your understanding of Mathematical & Statistical Operations.
- Problem ID: 35
- Problem key: 35-min-max-normalization
- URL: https://datacrack.app/solve/35-min-max-normalization
- Difficulty: easy
- Topic: Mathematical & Statistical Operations
- Module: NumPy Foundations
Problem Statement
# 🧩 Min-Max Normalization
---
### 🎯 Goal
Min-max normalization (feature scaling) is a mandatory preprocessing step for many ML algorithms. This is the NumPy version of the pure-Python problem you solved earlier — now fully vectorized, no loops needed.
$$
x_{\text{norm}} = \frac{x - x_{\min}}{x_{\max} - x_{\min}}
$$
---
### 🔍 Why Normalize?
Without normalization, features with large ranges dominate distance-based models (KNN, SVM) and cause slow convergence in gradient descent. After min-max normalization, all features lie in [0, 1].
---
### 💻 Task
Implement `min_max_normalize(data)` using **vectorized NumPy** (no Python loops).
---
### 📥 Input
- `data`: list of numbers
### 📤 Output
- List of normalized floats in [0.0, 1.0]
---
### 🧩 Starter Code
```python
import numpy as np
def min_max_normalize(data):
"""
Apply min-max normalization to scale values to [0, 1].
Args:
data (list): Input numbers
Returns:
list[float]: Normalized values in [0, 1]
"""
arr = np.array(data, dtype=float)
# 🧠 TODO:
pass
```
---
### 💡 Example
```python
min_max_normalize([0, 5, 10])
# Expected: [0.0, 0.5, 1.0]
min_max_normalize([-10, 0, 10])
# Expected: [0.0, 0.5, 1.0]
```
---
### 🔑 Key Concepts
- `arr.min()` and `arr.max()` — scalar aggregations, no axis needed for 1D
- `(arr - min_val)` — broadcasting: scalar subtracted from every element
- The entire formula applies vectorized in one expressionStarter Code
import numpy as np
def min_max_normalize(data):
"""
Apply min-max normalization to scale values to [0, 1].
Args:
data (list): Input numbers
Returns:
list[float]: Normalized values in [0, 1]
"""
arr = np.array(data, dtype=float)
# 🧠 TODO:
pass