MCPcopy Create free account
hub / github.com/scikit-learn/scikit-learn / Normalizer

Class Normalizer

sklearn/preprocessing/_data.py:2092–2225  ·  view source on GitHub ↗

Normalize samples individually to unit norm. Each sample (i.e. each row of the data matrix) with at least one non zero component is rescaled independently of other samples so that its norm (l1, l2 or inf) equals one. This transformer is able to work both with dense numpy arrays and

Source from the content-addressed store, hash-verified

2090
2091
2092class Normalizer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator):
2093 """Normalize samples individually to unit norm.
2094
2095 Each sample (i.e. each row of the data matrix) with at least one
2096 non zero component is rescaled independently of other samples so
2097 that its norm (l1, l2 or inf) equals one.
2098
2099 This transformer is able to work both with dense numpy arrays and
2100 scipy.sparse matrix (use CSR format if you want to avoid the burden of
2101 a copy / conversion).
2102
2103 Scaling inputs to unit norms is a common operation for text
2104 classification or clustering for instance. For instance the dot
2105 product of two l2-normalized TF-IDF vectors is the cosine similarity
2106 of the vectors and is the base similarity metric for the Vector
2107 Space Model commonly used by the Information Retrieval community.
2108
2109 For an example visualization, refer to :ref:`Compare Normalizer with other
2110 scalers <plot_all_scaling_normalizer_section>`.
2111
2112 Read more in the :ref:`User Guide <preprocessing_normalization>`.
2113
2114 Parameters
2115 ----------
2116 norm : {'l1', 'l2', 'max'}, default='l2'
2117 The norm to use to normalize each non zero sample. If norm='max'
2118 is used, values will be rescaled by the maximum of the absolute
2119 values.
2120
2121 copy : bool, default=True
2122 Set to False to perform inplace row normalization and avoid a
2123 copy (if the input is already a numpy array or a scipy.sparse
2124 CSR matrix).
2125
2126 Attributes
2127 ----------
2128 n_features_in_ : int
2129 Number of features seen during :term:`fit`.
2130
2131 .. versionadded:: 0.24
2132
2133 feature_names_in_ : ndarray of shape (`n_features_in_`,)
2134 Names of features seen during :term:`fit`. Defined only when `X`
2135 has feature names that are all strings.
2136
2137 .. versionadded:: 1.0
2138
2139 See Also
2140 --------
2141 normalize : Equivalent function without the estimator API.
2142
2143 Notes
2144 -----
2145 This estimator is :term:`stateless` and does not need to be fitted.
2146 However, we recommend to call :meth:`fit_transform` instead of
2147 :meth:`transform`, as parameter validation is only performed in
2148 :meth:`fit`.
2149

Calls 1

StrOptionsClass · 0.90

Used in the wild real call sites across dependent graphs

searching dependent graphs…