I have been struggling to find proof for that but I couldnt

Every time I prepare dataset I face the same issue

when a column is a classification such as CountryCode or TaskType in this dataset

TaskType  CountryCode  Target
1         61           Red
1         962          Yellow
2         1            Yellow
6         61           Yellow
4         81           Red
2         1            Blue
1         61           Red
2         962          Green
4         61           Blue

if I applied the dataset as to different models such as linear regression, SVM, KNN, etc.

will these model consider CountryCode and TaskType as numeric fields and treat them as continuous data?

Shall I One Hot Encode these features before using them?

what is the best way to handle this scenario?

  • $\begingroup$ What language are you using? $\endgroup$ Commented Aug 13, 2019 at 19:52
  • $\begingroup$ @fractalnature Python $\endgroup$
    – asmgx
    Commented Aug 13, 2019 at 22:20
  • $\begingroup$ orges-leka.de/automatic_feature_engineering.html maybe relevant in your situation. $\endgroup$
    – user42229
    Commented Aug 31, 2019 at 4:39

1 Answer 1


An intuitive explanation, why we should encode categorical features, is that otherwise there will be absolutely another sense of "closeness" between features of the same type. The model will treat this features as continuous and as a result if you have two points in your feature space (p1 with CountryCode 61 and p2 CountryCode 962) and then you add the third point p3 with CountryCode 81, then model will miss out, that it can't evaluate distances between 61, 962 and 81.


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.