scikit-learn/scikit-learn — pull request #3243 by mjbommar (2014-06-04 17:42:49+00:00)
Title: Make LabelEncoder more friendly to new labels

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_
* ``"nan"``: return np.nan for unseen/new labels
* ``"update"``: update ``classes_`` with new IDs ``[N, ..., N+m-1]`` for ``m`` new labels and assign

Tests and documentation updates included.