I have encoded categorical variables to numerical values. As we know that for feeding values to Linear Algorithms like SVM or KNN, we scale the values for columns having large variations.

I have three label encoded columns, one of which has unique values from 1-3, another has 1-150 and another has 0,1,-1 where -1 represents missing values. How will the MinMaxScaler affect here? Or it is not needed to scale these columns? If not, how can I avoid these specific columns? Generally we scale the whole dataframe.

P.S. I'm using LinearSVC algorithm.


1 Answer 1


Sounds like you should use a OneHotEncoder instead of a LabelEncoder since you are trying to encode non-ordinal data such as missing values. Also, one hot encoded values don't get affected by the MinMaxScaler, so that should be fine.

If MinMaxScaling makes sense is dependent on the categories. If your categories are ordinal, like [1,2,3] is [low, medium, high], then it still makes sense to use a LabelEncoder with a MinMaxScaler.

But if you have non-ordinal categorical values, like [-1,0,1] for [MISSING, DOG, CAT], then it would be better to use a OneHotEncoder instead of forcing ordinality with a LabelEncoder. Otherwise the algorithms you will use will make the assumption that the distance MISSING-DOG is longer than MISSING-CAT, which makes no sense.

  • $\begingroup$ my other column is having 150 unique label encoded values, what to do with that ? My dataset size is around 45k $\endgroup$ Jan 15, 2019 at 8:33
  • $\begingroup$ Can you give examples of labels? But the same still applies, if they are ordinal then you can use LabelEncoder, otherwise use OneHotEncoder. My hunch is that you really should be using one hot for all of the categorical values. $\endgroup$ Jan 15, 2019 at 8:57
  • $\begingroup$ there are around 150 unique statements (text), and i'm doing label encoding because my data size is around 45k. So when I label encode I'll have values starting from 1 to 150. In that case, what will be the effect of scaling? Because here one hot encoding will become meaningless $\endgroup$ Jan 17, 2019 at 8:54
  • $\begingroup$ or like when you have 150 unique text values, there is more efficient way to use that feature to increase my model accuracy? $\endgroup$ Jan 17, 2019 at 8:59
  • $\begingroup$ Can you give examples of these text values? Why is one hot encoding meaningless? The way I see it label encoding is meaningless since you encode them in a non-ordinal fashion which makes it impossible for a linear model to learn anything useful. Let's say you use linear regression and encode ['cat', 'dog', 'mouse'] to [1, 2, 3], then you'll get cat=1*coeff and mouse=3*coeff, which is a false relation made by the label encoder. With one hot encoding each unique text can be assigned a coefficient. $\endgroup$ Jan 17, 2019 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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