Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is the np.clip redundant for the min-max normalization

What’s the range of the default min-max normalization? Is it [0, 1] or [−1, 1] or both? How to get the range of [-1,1]?

X_scaled = (X - X_min)/(X_max - X_min)

And the numpy clip:

X_scaled_clipped = np.clip((X - X_min)/(X_max - X_min), 0, 1)

Is the np.clip(..., 0, 1) redundant here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This transformation:

def minmax_xform(x):
    x_max = np.amax(x)
    x_min = np.amin(x)
    return (x - x_min) / (x_max - x_min)

Gives you values in the [0, 1] range.

To get to the [-1, 1] range, just multiply by 2 (the size of the new range — the new maximum minus the new minimum) and add -1 (the new minimum):

def minmax_xform(x, max_=1, min_=-1):
    x_max = np.amax(x)
    x_min = np.amin(x)
    size = (max_ - min_)
    return size * (x - x_min) / (x_max - x_min) + min_

The clipping would be redundant.

Note that all this assumes no NaNs or infs, which should be addressed separately.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading