July 2017
Intermediate to advanced
382 pages
9h 13m
English
Similar to standardization, normalization is the process of scaling individual samples to have unit norm. I'm sure you know that the norm stands for the length of a vector, and can be defined in different ways. We discussed two of them in the previous chapter: the L1 norm (or Manhattan distance) and the L2 norm (or Euclidean distance).
In scikit-learn, our data matrix X can be normalized using the normalize function, and the l1 norm is specified by the norm keyword:
In [5]: X_normalized_l1 = preprocessing.normalize(X, norm='l1')... X_normalized_l1Out[5]: array([[ 0.2, -0.4, 0.4], [ 1. , 0. , 0. ], [ 0. , 0.5, -0.5]])
Similarly, the L2 norm can be computed by specifying norm='l2':
In [6]: X_normalized_l2 = preprocessing.normalize(X, ...
Read now
Unlock full access