v Rescale A Feature - Machine Learning

Rescale A Feature

Preliminaries

# Load libraries
from sklearn import preprocessing
import numpy as np

Create Feature

# Create feature
x = np.array([[-500.5], 
              [-100.1], 
              [0], 
              [100.1], 
              [900.9]])

Rescale Feature Using Min-Max

# Create scaler
minmax_scale = preprocessing.MinMaxScaler(feature_range=(0, 1))

# Scale feature
x_scale = minmax_scale.fit_transform(x)

# Show feature
x_scale
array([[ 0.        ],
       [ 0.28571429],
       [ 0.35714286],
       [ 0.42857143],
       [ 1.        ]])