Feature names from OneHotEncoder

A list with the original column names can be passed to get_feature_names.

>>> encoder.get_feature_names(['Sex', 'AgeGroup'])

array(['Sex_female', 'Sex_male', 'AgeGroup_0', 'AgeGroup_15',
       'AgeGroup_30', 'AgeGroup_45', 'AgeGroup_60', 'AgeGroup_75'],
      dtype=object)
  • DEPRECATED: get_feature_names is deprecated in 1.0 and will be removed in 1.2. Please use get_feature_names_out instead.
    • As per sklearn.preprocessing.OneHotEncoder.
>>> encoder.get_feature_names_out(['Sex', 'AgeGroup'])

array(['Sex_female', 'Sex_male', 'AgeGroup_0', 'AgeGroup_15',
       'AgeGroup_30', 'AgeGroup_45', 'AgeGroup_60', 'AgeGroup_75'],
      dtype=object)

Leave a Comment