# Determining the Quality of a Dataset in Clustering Terms
## 2 Materials and Methods
### Methodology
#### 2.2.4 Optimal Cluster Number Selection Methods  
The clustering algorithms belong to the unsupervised learning group, which means that it is impossible to compare the results with the original classes to verify the clustering accuracy. Therefore, for this task, a number of coefficients exist to assess the clustering quality based on differences between observations in the same groups and between observations from different groups. At the outset, two commonly used methods are presented: the elbow method and the silhouette method. The elbow method is based on measuring the within-cluster sum of squares errors (\(WSS\)) for a varying cluster number \(k\) and then selecting a value \(k\), for which the change in \(WSS\) starts to decrease. The \(WSS\) is therefore defined as:  
\[WSS=\sum_{i=1}^{n}(x_{i}-\check{x})^{2},\]  
with \(x_{i}\) representing the \(i\)th row of a data set having \(n\) rows, and \(\check{x}\) representing the average value in the cluster. The idea behind the elbow method is that the explained variability changes rapidly for a small number of clusters and then slows down, resulting in an elbow in the curve [19]. The point at which the so-called elbow is formed indicates the number of clusters that should be optimal in a given clustering algorithm. The silhouette coefficient is a slightly stricter method than the previously described one, but it is better at identifying relationships within and between groups. For consecutive observations \(i\) belonging to the analysed data, the coefficient is defined as [20]  
\[S(i)=\frac{b(i)-a(i)}{max(a(i),b(i))},\]  
whereby \(b(i)\) is the smallest mean observation distance \(i\) to all points in any other cluster, and \(a(i)\) is the mean distance \(i\) from all other points in the same group. For example, assuming we have three clusters \(\mathcal{A}\), \(\mathcal{B}\) and \(\mathcal{C}\) and observation \(i\) belongs to cluster \(\mathcal{C}\), then \(b(i)\) is calculated by measuring the mean distance \(i\) from each point in cluster \(\mathcal{A}\), the mean distance \(i\) from each point in cluster \(\mathcal{B}\) and takes the smallest value. The silhouette coefficient for the dataset is the mean of the silhouette coefficient for individual points. This measure indicates whether individual points are correctly assigned to their clusters. When using this coefficient, we can use the following interpretations:\(S(i)\) close to 0 means that the point is between two clusters. * If \(S(i)\) is close to \(-1\), then the studied point should be in a different cluster. * If \(S(i)\) is close to 1, then the point belongs to the \"correct\" cluster. The described methods were supplemented by two less classic ones. The Calinski-Harabasz index is based on the assumption that clusters are very compact and are sufficiently distant from each other to form a good distribution. The index is calculated by dividing the variance of the sums of squares of the distances of individual objects to their cluster centre by the sum of squares of the distance between the cluster centres. The higher that index value, the better the division. The formula for the Calinski-Harabasz index is defined as [21]: \[CH_{k}=\frac{BCSM}{k-1}\times\frac{n-k}{WCSM},\] where \(k\) is the number of clusters formed from a set of \(n\) observations, \(BCSM\) (_between cluster scatter matrix_) determines the separation between groups and \(WCSM\) (_Within cluster scatter matrix_) determines the compactness within clusters. A higher value of the CH index means the clusters are dense and well-separated, although there is no \"acceptable\" cut-off value. We need to choose the solution which gives a peak or at least an abrupt elbow on the line plot of CH indices. On the other hand, if the line is smooth (horizontal, ascending or descending) then there is no such reason to prefer one solution over others. Similarly to the silhouette method and the Calinski-Harabasz method, the Davies-Bouldin method tries to focus on both the separation and compactness of the clusters.