Answers for "how to normalize data in python"

5

normalize data python

>>> from sklearn import preprocessing
>>>
>>> data = [100, 10, 2, 32, 31, 949]
>>>
>>> preprocessing.normalize([data])
array([[0.10467389, 0.01046739, 0.00209348, 0.03349564, 0.03244891,0.99335519]])
Posted by: Guest on June-08-2020
1

How to normalize the data to get to the same range in python pandas

# Assuming same lines from your example
cols_to_norm = ['Age','Height']
survey_data[cols_to_norm] = survey_data[cols_to_norm].apply(lambda x: (x - x.min()) / (x.max() - x.min()))
Posted by: Guest on June-16-2020
1

feature scaling in python

from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
from sklearn.linear_model import Ridge
X_train, X_test, y_train, y_test = train_test_split(X_data, y_data,
                                                   random_state = 0)

X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)
Posted by: Guest on April-27-2020
0

data normalization python

from sklearn import preprocessing
normalizer = preprocessing.Normalizer().fit(X_train)  
X_train = normalizer.transform(X_train)
X_test = normalizer.transform(X_test)
Posted by: Guest on January-30-2021
0

Scaling features to a range

# Scaling features to a range using MaxAbsScaler

X_train = np.array([[ 1., -1.,  2.],
                    [ 2.,  0.,  0.],
                    [ 0.,  1., -1.]])

max_abs_scaler = preprocessing.MaxAbsScaler()
X_train_maxabs = max_abs_scaler.fit_transform(X_train)
X_train_maxabs
# array([[ 0.5, -1.,  1. ],
#        [ 1. ,  0. ,  0. ],
#        [ 0. ,  1. , -0.5]])
X_test = np.array([[ -3., -1.,  4.]])
X_test_maxabs = max_abs_scaler.transform(X_test)
X_test_maxabs
# array([[-1.5, -1. ,  2. ]])
max_abs_scaler.scale_
# array([2.,  1.,  2.])
Posted by: Guest on April-16-2020

Python Answers by Framework

Browse Popular Code Answers by Language