Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from sklearn.preprocessing import OrdinalEncoder
- enc = OrdinalEncoder()
- X = [['Male', 1], ['Female', 3], ['Female', 2]]
- enc.fit(X)
- print(enc.categories_)
- #Output: [array(['Female', 'Male'], dtype=object), array([1, 2, 3], dtype=object)]
- encoding = enc.categories_
- encoding_sex = dict(zip((encoding[0]), range(len(encoding[0]))))
- print(encoding_sex)
- # Output: {'Female': 0, 'Male': 1}
- encoding = enc.categories_
- encoding_feature = lambda x: dict(zip(x, range(len(x))))
- encoding_full = [encoding_feature(feature_elem) for feature_elem in encoding]
- print(encoding_full)
- # Output: [{'Female': 0, 'Male': 1}, {1: 0, 2: 1, 3: 2}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement