If it’s worthwhile to normalize an inventory of numbers in Python, then you are able to do the next:
Possibility 1 – Utilizing Native Python
record = [6,1,0,2,7,3,8,1,5]
print('Unique Checklist:',record)
xmin = min(record)
xmax=max(record)
for i, x in enumerate(record):
record[i] = (x-xmin) / (xmax-xmin)
print('Normalized Checklist:',record)
Possibility 2 – Utilizing MinMaxScaler
from sklearn
import numpy as np
from sklearn import preprocessing
record = np.array([6,1,0,2,7,3,8,1,5]).reshape(-1,1)
print('Unique Checklist:',record)
scaler = preprocessing.MinMaxScaler()
normalizedlist=scaler.fit_transform(record)
print('Normalized Checklist:',normalizedlist)
You can even specify the vary
of the MinMaxScaler()
.
import numpy as np
from sklearn import preprocessing
record = np.array([6,1,0,2,7,3,8,1,5]).reshape(-1,1)
print('Unique Checklist:',record)
scaler = preprocessing.MinMaxScaler(feature_range=(0, 3))
normalizedlist=scaler.fit_transform(record)
print('Normalized Checklist:',normalizedlist)