How to Normalize and Standardize All Columns

Asked 1 years ago, Updated 1 years ago, 87 views

There is data (da_all) stored in the csv file in column 12*30 and when I tried to normalize it with a program like the one below (excerpt where there might be a problem), it was normalized on a row-by-row.I'm having trouble reading all the data and making it a maximum value of 1, a minimum value of 0.Thank you for your cooperation.

from sklearn import preprocessing
import pickle
from sklearn.preprocessing import MinMaxScaler
scaler=preprocessing.MinMaxScaler([0,1])
scaler.fit(da_all)
data_del_mms = scaler.transform(da_all)

python python3 jupyter-notebook

2022-09-30 16:48

1 Answers

import numpy as np
from sklearn import preprocessing

data=np.random.randint(0,10,size=(3,10))
print(data)
# array([3,1,6,0,4,2,9,5,2,8],
#       [2, 8, 0, 6, 5, 0, 2, 9, 2, 6],
#       [4, 7, 2, 5, 9, 5, 4, 4, 8, 6]])

data=np.ravel(data) [None,:].T
scaler=preprocessing.MinMaxScaler()
scaler.fit(data)
data=scaler.transform(data)
data=data.T.reshape(3,10)
print(data)
# array([0.33333333, 0.111111, 0.66666667, 0.4444444,
#        0.22222222, 1.        , 0.55555556, 0.22222222, 0.88888889],
#       [0.22222222, 0.88888889, 0.        , 0.66666667, 0.55555556,
#        0.        , 0.22222222, 1.        , 0.22222222, 0.66666667],
#       [0.44444444, 0.77777778, 0.22222222, 0.55555556, 1.        ,
#        0.55555556, 0.44444444, 0.44444444, 0.88888889, 0.66666667]])


2022-09-30 16:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.