203 votes
Accepted

When to use One Hot Encoding vs LabelEncoder vs DictVectorizor?

There are some cases where LabelEncoder or DictVectorizor are useful, but these are quite limited in my opinion due to ...
user avatar
  • 6,678
55 votes

When to use One Hot Encoding vs LabelEncoder vs DictVectorizor?

While AN6U5 has given a very good answer, I wanted to add a few points for future reference. When considering One Hot Encoding(OHE) and Label Encoding, we must try and understand what model you are ...
user avatar
32 votes

K-Means clustering for mixed numeric and categorical data

In my opinion, there are solutions to deal with categorical data in clustering. R comes with a specific distance for categorical data. This distance is called Gower and it works pretty well.
user avatar
  • 573
27 votes

K-Means clustering for mixed numeric and categorical data

(In addition to the excellent answer by Tim Goodman) The choice of k-modes is definitely the way to go for stability of the clustering algorithm used. The clustering algorithm is free to choose any ...
user avatar
24 votes

K-Means clustering for mixed numeric and categorical data

This question seems really about representation, and not so much about clustering. Categorical data is a problem for most algorithms in machine learning. Suppose, for example, you have some ...
user avatar
  • 567
20 votes

How can I appropriately handle cleaning of gender data?

There are at least two general considerations to make: Domain-related If an attribute potentially has predictive power in your domain and more specifically for your task your models might benefit ...
user avatar
  • 4,877
16 votes

How to convert categorical data to numerical data in Pyspark

This can be done using StringIndexer in PySpark and the reverse using IndexToString for reference please check this: ...
user avatar
15 votes
Accepted

Why do we need to discard one dummy variable?

Simply put because one level of your categorical feature (here location) become the reference group during dummy encoding for regression and is redundant. I am quoting form here "A categorical ...
user avatar
  • 4,036
15 votes
Accepted

Confusion about Entity Embeddings of Categorical Variables - Working Example!

For those who are interested, I've spent some time, finally figured out that the problem was the way one has to prepare the categorical encoding for the Entity Embedding suitable for a neural network ...
user avatar
  • 4,036
14 votes

How can I do classification with categorical data which is not fixed?

It is very good question; in fact this problem has been around for a while and I have not yet found the perfect solution. Yet more than happy to share my experience: Avoid one-hot-encode as much as ...
user avatar
  • 4,036
12 votes
Accepted

Mass convert categorical columns in Pandas (not one-hot encoding)

If your categorical columns are currently character/object you can use something like this to do each one: ...
user avatar
11 votes

Clustering for mixed numeric and nominal discrete data

Taking a stab: I am trying to identify a clustering technique with a similarity measure that would work for categorical and numeric binary data. Gower Distance is a useful distance metric when the ...
user avatar
11 votes
Accepted

Is there an asymmetric version of nominal correlation?

I found what I was looking for - it's called Theil's U, or the Uncertainty Coefficient. I've used it in this Kaggle kernel, you can check it out for an example and code implementation in Python EDIT:...
user avatar
  • 679
10 votes

One Hot encoding for large number of values

If you really care about the number of dimensions, you still can try to apply a dimensionality reduction algorithm, such as PCA (Principal Component Analysis) or LDA (Linear Discriminant Analysis), ...
user avatar
  • 589
10 votes
Accepted

How can I dynamically distinguish between categorical data and numerical data?

I'm not aware of a foolproof way to do this. Here's one idea off the top of my head: Treat values as categorical by default. Check for various attributes of the data that would imply it is actually ...
user avatar
  • 578
9 votes

How can I appropriately handle cleaning of gender data?

It is quite an interesting question. I guess that you can call it "dealing with non-binary gender roles in a binary language" or something like this. In the past I did once something similar. I ...
user avatar
8 votes

How to combine PCA and MCA on mixed data?

You may want to use Factor analysis of mixed data. It allows you to do dimension reduction on a complete data set. A R implementation could be found in the FactoMineR package. But this function ...
user avatar
  • 241
8 votes

How to deal with categorical feature of very high cardinality?

This is an old question. I am surprised that I don't see anyone mentioned Mean Encoding (a.k.a Target Encoding). It is very popular in supervised learning problems. Besides, I have seen people use ...
user avatar
  • 181
8 votes

How to combine categorical and continuous input features for neural network training

There's three main approaches to solving this: Building two models separately and then training an ensemble algorithm that receives the output of the two models as an input Concating all the data ...
user avatar
8 votes
Accepted

How to handle columns with categorical data and many unique values

For categorical columns, you have two options : Entity Embeddings One Hot Vector For a column with 145 values, I would use one hot encoding and Embedding for ~3k values. This decision might change ...
user avatar
  • 2,191
8 votes

Why does frequency encoding work?

Check this post. In the cases where the frequency is related somewhat with the target variable, it helps the model to understand and assign the weight in direct and inverse proportion, depending on ...
user avatar
7 votes

K-Means clustering for mixed numeric and categorical data

You should not use k-means clustering on a dataset containing mixed datatypes. Rather, there are a number of clustering algorithms that can appropriately handle mixed datatypes. Some possibilities ...
user avatar
7 votes

K-Means clustering for mixed numeric and categorical data

It depends on your categorical variable being used. For ordinal variables, say like bad,average and good, it makes sense just to use one variable and have values 0,1,2 and distances make sense here(...
user avatar
  • 349
7 votes

Using NLP to automate the categorization of user description

One way to handle this is to use 'supervised classification'. In this model, you manually classify a subset of the data and use it to train your algorithm. Then, you feed the remaining data into your ...
user avatar
7 votes

One-Hot Vector representation vs Label Encoding for Categorical Variables

The main difference I can think of is that using one-hot encoding will mean that all your strings will be at the same (hamming) distance from each other, while using a scalar value means that ...
user avatar
7 votes
Accepted

How to deal with categorical feature of very high cardinality?

One-hot-encoded ZIP codes shouldn't present a problem with modern tools, where features can be much wider (millions, billions even), but if you really want you could aggregate area codes into regions, ...
user avatar
  • 10.4k
7 votes
Accepted

Why after adding categorical data the Linear Regression fails?

One possible reason is that when you use one-hot-encoding for categorical data, you should set the intercept property in the function to be False: ...
user avatar
  • 1,399
7 votes
Accepted

Pandas categorical variables encoding for regression (one-hot encoding vs dummy encoding)

One advantage of get_dummies is that it can operate on values other than integers (so you don't need the LabelEncoder) and ...
user avatar
  • 5,995
7 votes
Accepted

Why don't tree ensembles require one-hot-encoding?

The encoding leads to a question of representation and the way that the algorithms cope with the representation. Let's consider 3 methods of representing n categorial values of a feature: A single ...
user avatar
  • 2,593
7 votes

Different number of features in train vs test

Even though @Jekaterina Kokatjuhha's answer is accepted, I completely disagree with what it suggests. You should never make use of your test set when creating your pipeline. Technically, you don't ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible