# Mixed types of data for clustering

I have the following types of data for clustering - Numeric, Categorical and Latitude Longitude data for a location in one dataframe in python. I would like to know how can I go about doing clustering when the data is mixed to this degree.

Can I DBSCAN or hierarchical clustering and what do I need to do to convert categorical data to numeric. Same with geo location data.

You don't need to convert the attributes to numeric data for DBSCAN nor for HAC (hierarchical clustering).

What you need is a distance function.

While there are some such as Gower's, these are just heuristics.

If you want really good results, you need to carefully design a proper distance function that is able to quantify how similar records are for your purpose. This is very much usage dependent, and hence you cannot find the answer already solved for you.

As @Anony-Mousse specify it you need a distance function fitting with your data nature.

You have multiple possibilities, convert all your data as categorical, more specifically as binary data applying one hot encoding for example for categrorical data and by bucketing your scalar data.

You can also convert all your data into scalar type, applying dimentionality reduction (PCA, t-SNE, UMAP,...)

If you desire to keep your data as mixed (scalar and binary), Gower distance is a good start, or you can combine Euclidean(scalar) + $$\alpha .$$Hamming(binary) where $$\alpha$$ rest to determine depending your need.

Concerning algorithms, classic DBScan and Hierarchical clustering are respectively $$O(n^2)$$ and $$O(n^3)$$, you could start with another example which is the $$K$$-$$Prototypes$$ and which is $$O(n)$$, the mixed equivalent of the $$KMeans$$. Here you can find a scala $$K$$-$$Prototypes$$ implementation with the basic mixed metric, and other algorithms working on mixed data.