👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I have a machine learning classification problem with 80% categorical variables. Must I use one hot encoding if I want to use some classifier for the classification? Can i pass the data to a classifier without the encoding?
I am trying to do the following for feature selection:
I read the train file:
num_rows_to_read = 10000 train_small = pd.read_csv("../../dataset/train.csv", nrows=num_rows_to_read)
I change the type of the categorical features to "category":
non_categorial_features = ["orig_destination_distance", "srch_adults_cnt", "srch_children_cnt", "srch_rm_cnt", "cnt"] for categorical_feature in list(train_small.columns): if categorical_feature not in non_categorial_features: train_small[categorical_feature] = train_small[categorical_feature].astype("category")
I use one hot encoding:
train_small_with_dummies = pd.get_dummies(train_small, sparse=True)
The problem is that the 3"rd part often get stuck, although I am using a strong machine.
Thus, without the one hot encoding I can"t do any feature selection, for determining the importance of the features.
What do you recommend?
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from How can I one hot encode in Python?, check other ast Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano How can I one hot encode in Python?
- Deutsch How can I one hot encode in Python?
- Français How can I one hot encode in Python?
- Español How can I one hot encode in Python?
- Türk How can I one hot encode in Python?
- Русский How can I one hot encode in Python?
- Português How can I one hot encode in Python?
- Polski How can I one hot encode in Python?
- Nederlandse How can I one hot encode in Python?
- 中文 How can I one hot encode in Python?
- 한국어 How can I one hot encode in Python?
- 日本語 How can I one hot encode in Python?
- हिन्दी How can I one hot encode in Python?
Prague | 2023-03-26
I was preparing for my coding interview, thanks for clarifying this - How can I one hot encode in Python? in Python is not the simplest one. Will use it in my bachelor thesis
Texas | 2023-03-26
Thanks for explaining! I was stuck with How can I one hot encode in Python? for some hours, finally got it done 🤗. Will use it in my bachelor thesis
San Francisco | 2023-03-26
Thanks for explaining! I was stuck with How can I one hot encode in Python? for some hours, finally got it done 🤗. Will use it in my bachelor thesis