In a dataset there may be many outliers which effects the performance of the model. We can deal with it by scaling the data. Here we will be using min-max scaler for this.
So this is the recipe on how we can can rescale features in Python.
from sklearn import preprocessing import numpy as np
We have imported numpy and preprocessing which is needed.
We have created a array with values on which we will perform operation.
x = np.array([[-500.5],
We have used min-max scaler to scale the data in the array in the range 0 to 1 which we have passed in the parameter. Then we have used fit transform to fit and transform the array according to the min max scaler.
minmax_scale = preprocessing.MinMaxScaler(feature_range=(0, 1))
x_scale = minmax_scale.fit_transform(x)
So the output comes as
[[-500.5] [-100.1] [ 0. ] [ 100.1] [ 900.9]] [[0. ] [0.28571429] [0.35714286] [0.42857143] [1. ]]