Loading content...
Interval normalization is a fundamental data preprocessing technique that rescales numerical values from their original range to a specified target interval. This transformation is essential in machine learning, data visualization, and signal processing, where features often need to be brought to a common scale for optimal algorithm performance.
Given a NumPy array x with values naturally spanning from a (minimum) to b (maximum), the goal is to linearly map all values to a new interval [c, d] where c is the target minimum and d is the target maximum.
The linear mapping formula that transforms any value xᵢ from the original range [a, b] to the target range [c, d] is:
$$f(x_i) = c + \frac{(d - c)}{(b - a)} \cdot (x_i - a)$$
Where:
This transformation can be understood as a two-step process:
Implement a Python function that performs interval normalization on a NumPy array. The function should:
x = np.array([0, 5, 10])
target_min = 2
target_max = 4[2.0, 3.0, 4.0]The input array has: • Minimum (a) = 0 • Maximum (b) = 10 • Range = 10 - 0 = 10
Applying the formula f(x) = 2 + (4-2)/(10-0) × (x - 0) = 2 + 0.2x: • f(0) = 2 + 0.2 × 0 = 2.0 • f(5) = 2 + 0.2 × 5 = 3.0 • f(10) = 2 + 0.2 × 10 = 4.0
The values are evenly distributed in the target interval [2, 4].
x = np.array([-10, 0, 10])
target_min = 0
target_max = 1[0.0, 0.5, 1.0]The input spans from -10 to 10 (range = 20). Normalizing to [0, 1]: • Minimum (-10) maps to 0.0 • Middle value (0) maps to 0.5 • Maximum (10) maps to 1.0
This is the standard min-max normalization to the unit interval, commonly used before feeding data into neural networks.
x = np.array([[1, 2], [3, 4]])
target_min = 0
target_max = 100[[0.0, 33.3333], [66.6667, 100.0]]For this 2×2 matrix with global min = 1 and max = 4 (range = 3): • f(1) = 0 + (100-0)/(4-1) × (1-1) = 0.0 • f(2) = 0 + (100/3) × (2-1) = 33.3333 • f(3) = 0 + (100/3) × (3-1) = 66.6667 • f(4) = 0 + (100/3) × (4-1) = 100.0
The 2D structure is preserved while all values are mapped to the [0, 100] range.
Constraints