Reputation: 1239
For variables with two categories, do they need to be One Hot Encoded? In my dataset I have a binary variable as either 1 or 0. Do I need to transform that variable in a pipeline for my model or do I leave it as is?
variable = np.array([0,0,0,1,0,1,0]).reshape(-1,1)
ohc = OneHotEncoder()
ohc.fit(variable)
Upvotes: 3
Views: 1692
Reputation: 2042
If your variable is already binary (only two classes: 0 and 1), you can say that this variable is already One Hot Encoded, so you don't need to to OneHotEncoder
again with Sklearn function.
Moreover, in general terms, if you binary variable is categorical, you have to transform it to numerical using LabelEncoder
. Anyway, in your example, your variable was already numerical.
Upvotes: 3