0
$\begingroup$

enter image description here

I was trying to encode the string values of the feature 'ProductCategory' into integer values but I got this error. Kindly help.

And I would also like to ask if label-encoding this feature would not force my model to misrepresent the integer values as 0<1<2. Thanks.

$\endgroup$
0
$\begingroup$

LabelEncoding, if not processed again before passing into the model, will impose an order on the categories (namely the 0<1<3) that you mentioned. Here, since it does not seem like you have a lot of categories, one-hot encoding is the easiest to implement and also more effective (the categorical values are nominal rather than ordinal here).

These two articles are a decent starting point for categorical encoding in Python: https://pbpython.com/categorical-encoding.html

https://medium.com/@contactsunny/label-encoder-vs-one-hot-encoder-in-machine-learning-3fc273365621

As for the TypeError, can you double check what variable type train_df is?

$\endgroup$

Your Answer

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

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