Binarize data (set feature values to 0 or 1) according to a threshold. Values greater than the threshold map to 1, while values less than or equal to the threshold map to 0. With the default threshold of 0, only positive values map to 1. Binarization is a common operation on text c
| 2293 | |
| 2294 | |
| 2295 | class Binarizer(OneToOneFeatureMixin, TransformerMixin, BaseEstimator): |
| 2296 | """Binarize data (set feature values to 0 or 1) according to a threshold. |
| 2297 | |
| 2298 | Values greater than the threshold map to 1, while values less than |
| 2299 | or equal to the threshold map to 0. With the default threshold of 0, |
| 2300 | only positive values map to 1. |
| 2301 | |
| 2302 | Binarization is a common operation on text count data where the |
| 2303 | analyst can decide to only consider the presence or absence of a |
| 2304 | feature rather than a quantified number of occurrences for instance. |
| 2305 | |
| 2306 | It can also be used as a pre-processing step for estimators that |
| 2307 | consider boolean random variables (e.g. modelled using the Bernoulli |
| 2308 | distribution in a Bayesian setting). |
| 2309 | |
| 2310 | Read more in the :ref:`User Guide <preprocessing_binarization>`. |
| 2311 | |
| 2312 | Parameters |
| 2313 | ---------- |
| 2314 | threshold : float, default=0.0 |
| 2315 | Feature values below or equal to this are replaced by 0, above it by 1. |
| 2316 | Threshold may not be less than 0 for operations on sparse matrices. |
| 2317 | |
| 2318 | copy : bool, default=True |
| 2319 | Set to False to perform inplace binarization and avoid a copy (if |
| 2320 | the input is already a numpy array or a scipy.sparse CSR matrix). |
| 2321 | |
| 2322 | Attributes |
| 2323 | ---------- |
| 2324 | n_features_in_ : int |
| 2325 | Number of features seen during :term:`fit`. |
| 2326 | |
| 2327 | .. versionadded:: 0.24 |
| 2328 | |
| 2329 | feature_names_in_ : ndarray of shape (`n_features_in_`,) |
| 2330 | Names of features seen during :term:`fit`. Defined only when `X` |
| 2331 | has feature names that are all strings. |
| 2332 | |
| 2333 | .. versionadded:: 1.0 |
| 2334 | |
| 2335 | See Also |
| 2336 | -------- |
| 2337 | binarize : Equivalent function without the estimator API. |
| 2338 | KBinsDiscretizer : Bin continuous data into intervals. |
| 2339 | OneHotEncoder : Encode categorical features as a one-hot numeric array. |
| 2340 | |
| 2341 | Notes |
| 2342 | ----- |
| 2343 | If the input is a sparse matrix, only the non-zero values are subject |
| 2344 | to update by the :class:`Binarizer` class. |
| 2345 | |
| 2346 | This estimator is :term:`stateless` and does not need to be fitted. |
| 2347 | However, we recommend to call :meth:`fit_transform` instead of |
| 2348 | :meth:`transform`, as parameter validation is only performed in |
| 2349 | :meth:`fit`. |
| 2350 | |
| 2351 | Examples |
| 2352 | -------- |
no outgoing calls
searching dependent graphs…