I took this example from the sklearn OneHotEncoder documentary page:
from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder(handle_unknown='ignore')
X = [['Male', 1], ['Female', 3], ['Female', 2]]
enc.fit(X)
enc.categories_
enc.transform([['Female', 1], ['Male', 4]]).toarray()
enc.inverse_transform([[0, 1, 1, 0, 0], [0, 0, 0, 1, 0]])
enc.get_feature_names()
I get:
ValueError: could not convert string to float: 'Male'.
When I replace "Male" and "Female" with numbers:
X = [['5', 1], ['4', 3], ['4', 2]]
I get :
AttributeError: 'OneHotEncoder' object has no attribute 'categories_'
My sklearn version is 0.19.1 Can someone reproduce this?