# How do we interpret the outputs of DBSCAN clustering?

I am starting to learn DBSCAN for clustering but the interpretation part of it seems to be tricky to understand.

dataset = np.vstack((quotient_times, quotient)).T

scaler = StandardScaler()
dataset = scaler.fit_transform(dataset)

db_scan = DBSCAN(eps=0.6, min_samples=1)
db_scan.fit(dataset)

colors = [int(i % 23) for i in db_scan.labels_]

plt.figure();
plt.title(fname)
plt.xlabel("time")
plt.ylabel("quotient")
plt.scatter(dataset[:, 0], dataset[:, 1], c=colors)
plt.legend()
plt.show()


This produces the following plot.

When i print the values of db_scan.labels_, I am getting

array([0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1])

I was expective my y-axis values from 0-1 and x-axis values from 1-7. Why do I have the negative scales both on the x-axis and y-axis? and how do we interpret these values and the plot?

Don't blindly copy code from the internet.

You copied code that scales data. Hence, the axis changed. But that wasn't DBSCAN, but that was you invoking StandardScaler.

It is important that you understand what you are doing... You have a time axis and a value axis. These are completely different, and computing Euclidean distance does not make any sense...

What you probably wanted to do with such data is GDBSCAN instead. For Generalized DBSCAN you would define two epsilon thresholds:

1. One threshold for time: how many time steps apart is still the same cluster?
2. One threshold for values: what difference in values is still the same cluster?
3. min_samples should always be at least 3, or you are not doing DBSCAN, but Single-Link clustering.

Then run GDBSCAN on that.

Since sklearn does not have GDBSCAN, you can emulate this here by scaling and maximum norm, but that is a bit hackish.

• you are right but there is no module gdbscan with the python library Commented Feb 24, 2019 at 12:41
• I don t think k-means is a good choice for such data, because of its sensitivity to outliers. As for your question, don't expect computers to guess. If you want to plot x and y, tell it to plot x and y. The error exactly tells you what parameter is wrong... Commented Feb 24, 2019 at 17:48
• OK thank you but why do you have to downvote the question then? I don't think that is fair. There is nothing wrong with being a beginner and that's how you learn new things. Commented Feb 24, 2019 at 18:06
• I just asked you for help if you don't think my question is not good enough, you just ignore it. Otherwise, I don't think being harsh and downvoting the question is fair at all. Nobody is born stupid and it is a matter of time and learning things through time. Thanks! Commented Feb 24, 2019 at 18:12
• Downvoting means "the question is not likely to help future visitors". This is nothing against you personally. It's just that the documentation of sklearn is fairly detailed, and the answer is there already, so the question is not too useful for others. Commented Feb 24, 2019 at 22:07

The output from db_scan.labels_ is the assigned cluster value for each of the points that you provide as input to the algorithm.

You provided 20 points, so there are 20 labels. As explained in the relevant documentation, you will see:

labels_ : array, shape = [n_samples] Cluster labels for each point in the dataset given to fit(). Noisy samples are given the label -1.

So each of your points was assigned to one of two clusters, and there were no points marked as noise (receiving a value of -1).

## Interpreting the clusters

Your plot shows the original data, plotted on the axes using the original values; only the colour encodes the cluster to which each point was assigned.

As with many clustering algorithms, DBSCAN measures the distance between points in some n-dimensional space. It uses parameters you provide to decide if points belong to the same group, based on their distance from one another.

Why do I have the negative scales both on the x-axis and y-axis?

The distance metrics used do not really care about the sign of the points (where they lie on an axis), simply the distances. In the case of DBSCAN, it is the Euclidean distance. There are other distances that you can pass to the metric parameter of the DBSCAN algorithm; here is the valid list.

• Check the DBSCAN documentation... Commented Feb 24, 2019 at 12:20