scikit-learn/scikit-learn — pull request #3483 by mjbommar (2014-07-24 19:00:52+00:00)
Title: Make LabelEncoder more friendly to new labels

This is a final, cleanly rebased version of PR 3243 (https://github.com/scikit-learn/scikit-learn/pull/3243) incorporating discussions.

## Summary:
This PR intends to make ``preprocessing.LabelEncoder`` more friendly for production/pipeline usage by adding a ``new_labels`` constructor argument.

Instead of always raising ``ValueError`` for unseen/new labels in transform, ``LabelEncoder`` may be initialized with new_labels as:
* ``"raise"``: current behavior, i.e., raise ``ValueError``; to remain default behavior
* ``"update"``: update classes with new IDs ``[N, ..., N+m-1]`` for m new labels and assign
* an integer value: set newly seen labels to have fixed value corresponding to this integer value

**N.B.**: Direct access to ``.classes_`` should be replaced with ``.get_classes()`` in order to properly handle the ``new_labels="update"``.

Tests and documentation updates included.