1
$\begingroup$

I am currently getting ready to preprocess my data for scikitlearn and was wondering if I should use one hot encoding or label encoding when working with values greater than 9. I may be wrong but when it comes to one hot encoding it can only work on values 0-9.

$\endgroup$
0
$\begingroup$

Generally, depends on the model you are going to use later. If you are planning to use a tree-based model, then label-encoding (or even frequency-encoding) works fine. However, if you plan on using a linear model or Neural network, then one-hot encoding works better. Using one-hot encoding in tree-based models might unnecessarily increase complexity (See this link).

Always strategize your preprocessing so that it benefits the model you have chosen.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I plan on using several models (Random Forest, Clustering, and Regression). $\endgroup$ – user251048 May 7 '19 at 23:41
  • $\begingroup$ Separately preprocess for each of them. Using the same preprocessed data for all algorithms is never advised. $\endgroup$ – vipulnj May 7 '19 at 23:49
  • $\begingroup$ okay thanks for the help. $\endgroup$ – user251048 May 8 '19 at 0:08
0
$\begingroup$

It depends on the meaning of the feature.

  • If sorting labels makes sense LabelEncoder/OrdinalEncoder is better choice (for example feature is damage in ["no", "light", "medium", "severe"])
  • Otherwise OneHotEncoder is a better choice (for example color in ["blue", "yellow", "orange"])
| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy