Data normalization or standardization is defined as the process of rescaling original data without changing its behavior or nature. We define new boundary (most common is (0,1),(-1,1)) and convert data accordingly. Data normalization technique is useful in classification algorithms involving neural network or a distance based algorithm (e.g. KNN, K-means).
Min-max normalization preserves the relationship among the original data values. If in future the input values comes to be beyond the limit of normalization, then it will encounter an error known as “out-of-bound error.”
Let’s see an example: Suppose the minimum and maximum values for price of house be $125,000 and $925,000 respectively. We need to normalize that price range in between 0,1, . We can use min- max normalization to transform any value between them (say, 300,000). In this case we use above formula with,
from sklearn import preprocessing import numpy as np X_train = np.array([[ 1., -1., 2.], [ 2., 0., 0.], [ 0., 1., -1.]]) min_max_scaler = preprocessing.MinMaxScaler() X_train_minmax = min_max_scaler.fit_transform(X_train) print(X_train_minmax)
b) Z-score Normalization/standardization( Zero mean normalization /standardization) : In this technique, the values are normalized based on the mean and standard deviation of attribute A. For Vi value of attribute A, normalized value Ui is given as,
where Avg(A) and Std(A) represents the average and standard deviation of values attribute A respectively.
Let’s see an example: Suppose that the mean and standard deviation of values for attribute income $54,000 and $16,000 respectively. With z-score normalization, a value of $73,000 for income is transformed to (73,000-54,000)/16,000=1.225.
from sklearn.preprocessing import StandardScaler X=[[101,105,222,333,225,334,556],[105,105,258,354,221,334,556]] print("Before standardisation X values are ", X) sc_X = StandardScaler()X = sc_X.fit_transform(X) print("After standardisation X values are ", X)
Lets understand it by an example: Suppose we have data set in which the value ranges from -9900 to 9877. In this case the maximum absolute value is 9900. So to perform decimal normalization, we divide each of values in data set by 10000 i.e j=4.(since it near to 9900).
Let’s understand it by an example. Suppose we are making a predictive model using dataset that contains the net worth of citizens of a country. For this data set we find that there is large variation in data. If we feed this data to train any model, then it may generate some undesirable results. So, to get rid of that we opt normalization.
Post a Comment