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.

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

$\endgroup$

1 Answer 1

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 and acknowledge you have read our privacy policy.

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