1# Scaling features to a range using MinMaxScaler
2
3X_train = np.array([[ 1., -1., 2.],
4 [ 2., 0., 0.],
5 [ 0., 1., -1.]])
6
7min_max_scaler = preprocessing.MinMaxScaler()
8X_train_minmax = min_max_scaler.fit_transform(X_train)
9X_train_minmax
10# array([[0.5 , 0. , 1. ],
11# [1. , 0.5 , 0.33333333],
12# [0. , 1. , 0. ]])
13
14X_test = np.array([[-3., -1., 4.]])
15X_test_minmax = min_max_scaler.transform(X_test)
16X_test_minmax
17# array([[-1.5 , 0. , 1.66666667]])
18
19min_max_scaler.scale_
20# array([0.5 , 0.5 , 0.33...])
21
22min_max_scaler.min_
23# array([0. , 0.5 , 0.33...])
1# Scaling features to a range using MaxAbsScaler
2
3X_train = np.array([[ 1., -1., 2.],
4 [ 2., 0., 0.],
5 [ 0., 1., -1.]])
6
7max_abs_scaler = preprocessing.MaxAbsScaler()
8X_train_maxabs = max_abs_scaler.fit_transform(X_train)
9X_train_maxabs
10# array([[ 0.5, -1., 1. ],
11# [ 1. , 0. , 0. ],
12# [ 0. , 1. , -0.5]])
13X_test = np.array([[ -3., -1., 4.]])
14X_test_maxabs = max_abs_scaler.transform(X_test)
15X_test_maxabs
16# array([[-1.5, -1. , 2. ]])
17max_abs_scaler.scale_
18# array([2., 1., 2.])