3
$\begingroup$

I recently tried to create a model for predicting what class a sample belongs to out of 160 possible classes. These classes of the target variable are just simple strings describing workouts like "Push-ups", "Sit-ups" etc. I used sklearn's method LabelEncoder to transform the target variable, and it assigned every class a number between 0 and 159. I know that the reason why we are supposed to do one-hot encoding for categorical features is to avoid telling an algorithm something nonsensical like "blue is greater than red". My question then becomes, doesn't LabelEncoder tell the sklearn algorithm that "push-ups" is less than or greater than "sit-ups" if both of them are assigned distinct numbers between 0-159? Why or why not? This feels like a very stupid question, but I had real trouble finding an answer anywhere online.

$\endgroup$
  • $\begingroup$ did you resolve this? $\endgroup$ – Maths12 Apr 6 '20 at 14:12
1
$\begingroup$

Welcome to the site! Do a google search for "one hot encoding" and all will become clear.

In a nutshell, don't think of it as numbers "assigned" of 0-159. It's more about a "slot" for each category and using one hot encoding to let the algorithm know which slot a particular record belongs to.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.