# How To Determine Number Of Clusters In T-SNE And Best Clustering Algorithm?

I used TSNE method to cluster my DataSet.

X_embedded = TSNE(n_components=2, verbose=1, perplexity=10, n_iter=600).fit_transform(binary)
kmeans = KMeans(init="k-means++", n_clusters=6, n_init=4)
kmeans.fit(X_embedded)

1. Why it just clusters my DataSet into 2 clusters?
2. What is The best method for clustering that?
3. How to determine Number Of Clusters ?

Here is my clusters's dispersion :

import seaborn as sns

sns.scatterplot(data = X_embedded)


• 0. Welcome to CV.SE. 1. I think you have a little programming mistake in your plotting. There are a few methodologies that might be relevant to your questions. Please see my answer below for more details. Jul 1, 2021 at 9:25
• @usεr11852 Thanks..Yes It has some problems...I used import plotly.express as px. And draw scatterPlot with that...And alsodata["x_component"]=X_embedded[:,0] data["y_component"]=X_embedded[:,1]...Is It true? Jul 1, 2021 at 14:50
• Yes, but please note that the order of components in t-SNE is arbitrary. (i.e. x_component do not have to be the first column of the transformed output) Jul 1, 2021 at 23:37

1. There are not only two clusters. What happens is that when plotting the data we do not define how the dots should be coloured, something like: plt.scatter(x = ..., y = ..., c = kmeans.predict(...)) should give you what you are after. (Side-note: the scatter-plot shown appears quite unstructured so I would not be very optimistic about a clustering algorithm doing well here)