#Unfortunately outputs an array instead of dataframe.Īrray_hot_encoded = ohe.fit_transform(data)ĭata_hot_encoded = pd.DataFrame(array_hot_encoded, index=data.index) # apply le on categorical feature columnsĭata = data.apply(lambda col: le.fit_transform(col))įrom sklearn.preprocessing import OneHotEncoder If you really need to do it this way: categorical_cols = įrom sklearn.preprocessing import LabelEncoder If you want to encode the data you should use OrdinalEncoder. LabelEncoder is not made to transform the data but the target (also known as labels) as explained here.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |