I am trying to encode an ordinal column by using the OrdinalEncoder from sklearn. Sample data could be the following:
from sklearn.preprocessing import OrdinalEncoder
import numpy as np
X = np.array([-1, -2, -3, 0, 1, 2, 3, 2, 1, 4, 1, 4, -1]).reshape(-1,1)
enc = OrdinalEncoder()
enc.fit(X)
enc.transform(X)
enc2 = OrdinalEncoder(categories = np.arange(-3, 5))
enc2.fit(X)
ValueError: Shape mismatch: if categories is an array, it has to be of shape (n_features,).
I want to be able to input the categories manually so the already existing question (Shape mismatch: if categories is an array, it has to be of shape (n_features,)) is not of much help. My problem is that I don't understand the error. The shape of the categories is (to my mind) correct:
np.arange(-3, 5).shape
Out [1]:(8,)
What am I missing?