String indices must be integers

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 012. Thanks.

Topic autoencoder encoding classification

Category Data Science


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?

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.