How to Normalize Data in Python

Normalization means rescaling of real-valued numeric attributes into a 0 to 1 range.
Data normalization is used in machine learning to make model training less sensitive to the scale of features. This allows our model to converge to better weights and, in turn, leads to a more accurate model.
Python provides the preprocessing
library, which contains the normalize
function to normalize the data. It takes an array in as an input and normalizes its values between 0 and 1. It then returns an output array with the same dimensions as the input.
from sklearn import preprocessing import numpy as np a = np.random.random((2, 3)) a = a*20 print("Data = ", a) # normalize the data attributes normalized = preprocessing.normalize(a) print("Normalized Data = ", normalized)
Output:
Data = [[10.01766389 4.76582892 2.4596835 ] [10.59777787 3.13478939 13.15589421]] Normalized Data = [[0.88160724 0.41941807 0.21646512] [0.6167993 0.18244729 0.76568375]]
Subscribe
Login
Please login to comment
0 Discussion