Scikit-learn's LabelBinarizer vs. OneHotEncoder

前端 未结 4 570
陌清茗
陌清茗 2020-11-30 00:37

What is the difference between the two? It seems that both create new columns, which their number is equal to the number of unique categories in the feature. Then they assig

4条回答
  •  清歌不尽
    2020-11-30 01:17

    The results of OneHotEncoder() and LabelBinarizer() are almost similar [there might be differences in the default output type.

    However, to the best of my understanding, LabelBinarizer() should ideally be used for response variables and OneHotEncoder() should be used for feature variables.

    Although, at present, I am not sure why do we need different encoders for similar tasks. Any pointer in this direction would be appreciated.

    A quick summary:

    LabelEncoder – for labels(response variable) coding 1,2,3… [implies order]

    OrdinalEncoder – for features coding 1,2,3 … [implies order]

    Label Binarizer – for response variable, coding 0 & 1 [ creating multiple dummy columns]

    OneHotEncoder - for feature variables, coding 0 & 1 [ creating multiple dummy columns]

    A quick example can be found here.

提交回复
热议问题