# How to plot categories after clustering

I am trying to plot the categories I have obtained via DBSCAN on a 30-dimensional dataset 12 categories, and I want to visualize them in a 2d plot.

My procedure was to reduce that 30-dimensional dataset to a 2-dimensional one using PCA, and then color the categories using the ones obtained before with the 30-dim dataset.

The inconsistency I am facing is that when plotting, the 'clusters' don't seem to match the logic of density of DBSCAN, which is the fact that leads me to think that my process is in the wrong order, but I dont wanna reduce dimensions and then cluster, and then go back to 30 dimensions again.

Is there any right order to follow?

EDIT

1) To expand, what I get with the first procedure: PCA, DBSCAN and then plotting is: which certainly looks much logical based on the densities.

2) But if I use DBSCAN on the 30-dim dataset and then reduce the dimensions and plot using the original categories is:

In both results I don't get the same results with the Nearest Neighbors knee that is used to choose an optimal epsilon in DBSCAN.

• (1) Cluster the samples using the 30-dimensional features, (2) Project these features to a 2-dimensional space, (3) Plot the 2-dimensional features with the labels created at (1). I think these are three steps you followed, which makes sense to me. Would you mind checking your codes, maybe? – inmybrain Feb 12 at 0:50
• Yes, I have added both plots to give you an idea. – astro_xyz Feb 12 at 16:01
• Thanks for the update. How about showing your codes here? Also, why do you think both procedures coincide with each other? – inmybrain Feb 13 at 0:52
• W/o your data & code,we can't say for sure. However, most likely, the DBSCAN is picking up clusters that are orthogonal to the 1st 2 PCs. That is, your data are spread widely in 2 directions (yielding PCs), but clustered in lower variance directions. When the clusters are projected onto the 1st 2 PCs, they seem incoherent. Note that DBSCAN & PCA look at your data through very different lenses, so they needn't necessarily see the same things. You may be interested in reading Examples of PCA where PCs with low variance are “useful” – gung - Reinstate Monica Feb 25 at 21:00