Skip to content

Commit 872c19e

Browse files
lucyleeowogrisel
andauthored
ENH Allows multiclass target in TargetEncoder (scikit-learn#26674)
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
1 parent 5763e5a commit 872c19e

File tree

4 files changed

+397
-73
lines changed

4 files changed

+397
-73
lines changed

doc/modules/preprocessing.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,19 @@ computed as an empirical Bayes estimate: :math:`m=\sigma_i^2/\tau^2`, where
903903
:math:`\sigma_i^2` is the variance of `y` with category :math:`i` and
904904
:math:`\tau^2` is the global variance of `y`.
905905

906+
For multiclass classification targets, the formulation is similar to binary
907+
classification:
908+
909+
.. math::
910+
S_{ij} = \lambda_i\frac{n_{iY_j}}{n_i} + (1 - \lambda_i)\frac{n_{Y_j}}{n}
911+
912+
where :math:`S_{ij}` is the encoding for category :math:`i` and class :math:`j`,
913+
:math:`n_{iY_j}` is the number of observations with :math:`Y=j` and category
914+
:math:`i`, :math:`n_i` is the number of observations with category :math:`i`,
915+
:math:`n_{Y_j}` is the number of observations with :math:`Y=j`, :math:`n` is the
916+
number of observations, and :math:`\lambda_i` is a shrinkage factor for category
917+
:math:`i`.
918+
906919
For continuous targets, the formulation is similar to binary classification:
907920

908921
.. math::

doc/whats_new/v1.4.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ Changelog
178178
to :ref:`metadata routing user guide <metadata_routing>`. :pr:`26789` by
179179
`Adrin Jalali`_.
180180

181+
:mod:`sklearn.preprocessing`
182+
............................
183+
184+
- |Enhancement| :class:`preprocessing.TargetEncoder` now supports `target_type`
185+
'multiclass'. :pr:`26674` by :user:`Lucy Liu <lucyleeow>`.
186+
181187
:mod:`sklearn.model_selection`
182188
..............................
183189

0 commit comments

Comments
 (0)