Python for Machine Learning – Part 22 – Min Max Scaler

Topics to be covered

Feature Scalaing
1. Min Max Scalar
2. Standard Scalar
3. Normalize
4. Binarize
”’

from sklearn import preprocessing
import numpy as np

x = np.array([[-400],
[-100],
[0],
[100],
[400]])

minmaxscaler = preprocessing.MinMaxScaler(feature_range=(0,1))

x_scaler = minmaxscaler.fit_transform(x)

print(x_scaler)

”’ (Xi – Xmin) / (Xmax – Xmin)
(-100 -(-400))/(400 -(-400) )
(-100 + 400) / (400 + 400)
300/800 = 3/8”’

###################### Applying it to 3X3 Matrix

x1 = np.array([[1,2,3],
[4,5,6],
[7,8,9]])

minmaxscaler1 = preprocessing.MinMaxScaler(feature_range=(0,1))

x_scaler1 = minmaxscaler1.fit_transform(x1)

print(x_scaler1)

################################## Appying ti to a Pandas Dataset

import pandas as pd

dataset = pd.read_csv(‘Age-Salary.csv’)

features = dataset.iloc[:,[2,3]].values

minmaxscaler_as = preprocessing.MinMaxScaler(feature_range=(0,2))

features_scale = minmaxscaler_as.fit_transform(features)

Leave a Comment

Your email address will not be published. Required fields are marked *