# H&E Multi-Laboratory Staining Variance Exploration with Machine Learning
## 2 Materials and Methods
### Preprocessing, Feature Extraction, and Engineering (Unsupervised Learning)
#### 2.3.7 Model Selection and Figure of Merit  
We grid-searched up to 24 clusters iterating the k-means ++ algorithm 500 times per run. The figure of merit used for judging the quality of clusters and the selection criterion \begin{table}
\begin{tabular}{c c} \hline
1. & Randomly select one data point \(\mathbf{x}_{c}\) from the available data points \(\{\mathbf{x}_{1}x_{2}x_{3}\ldots x_{i}\}\) to serve as a centroid \(C\). \\
2. & Compute \(D(\mathbf{x})\), the distance of each non-selected datapoint \(\mathbf{x}\) to the nearest selected cluster centroid \(C\). \\
3. & Select a new \(C\) from the available data points \(x\) such that the new point has a probability of being chosen directly proportional to the distance \(D(\mathbf{x})^{2}\) to the nearest, previously selected \(C\). \\
4. & Repeat Steps 2 and 3 until \(k\) centroids \(C_{k}\) are sampled. \\
5. & When Step 4 is complete, continue with the standard k-means algorithm. \\ \hline \end{tabular}
\end{table} 
Table 1: k-means++ Pseudo-Algorithmic Steps. Figure 6: Explained cumulative variance by principal components. of the grid-search was the average silhouette coefficient using the Euclidian distance, defined as:  
\[d(\mathbf{x},\mathbf{q})=\sqrt{\sum_{v=1}^{b}(\mathbf{x}_{v}-\mathbf{q}_{v})^{2}} \tag{8}\]  
where \(\mathbf{x}_{v},\mathbf{q}_{v}\) are two points in Euclidian space of \(b\) dimensions. The silhouette coefficient [27] or score is often used to determine cluster quality. Formally [28; 29], for a single data point \(x\), the silhouette coefficient is calculated as:  
\[S(\mathbf{x})=\frac{b(\mathbf{x})-a\ (\mathbf{x})}{\max(a(\mathbf{x}),b(\mathbf{x}))} \tag{9}\]  
where \(a(\mathbf{x})\) is the average distance of data point \(\mathbf{x}\) from the cluster \(C_{u}\) to the remaining data points \(\mathbf{x}_{u}\) from the same cluster \(C_{u}\), referred to as intra-cluster distance and defined as:  
\[a(\mathbf{x})=\frac{1}{n_{u}-1}\sum_{\mathbf{x}_{u}\in C_{u}}d(\mathbf{x},\mathbf{x}_{u}) \tag{10}\]  
where \(n_{u}\) is the total data points counted in cluster \(C_{u}\), and \(d\) is the distance metric. The other component in Equation (9), \(b(\mathbf{x})\), refers to the minimum average distance of datapoint \(\mathbf{x}\) to data points \(\mathbf{x}_{y}\) that belong to the cluster \(C_{y}\) where \(y\
eq u\); this is referred to as intra-cluster distance and is expressed as:  
\[b(\mathbf{x})=\min_{ \begin{subarray}{c}y=1\\ y\
eq u\end{subarray} }^{k}\frac{1}{n_{y}}\sum_{\mathbf{x}\in C_{y}}d(\mathbf{x},\mathbf{x} _{y}) \tag{11}\]  
where, similarly to Equation (10), \(n_{y}\) is the total data point count in cluster \(C_{y}\) and \(d\) the distance metric. The average silhouette coefficient for the cluster \(C_{u}\) can then be expressed as:  
\[S(C_{u})=\frac{1}{n_{u}}\sum_{\mathbf{x}\in C_{u}}S(\mathbf{x}) \tag{12}\]  
Finally, for clusters \(C=\{C_{1},C_{2},\ldots,C_{k}\}\), the average coefficient score is simply:  
\[SIL_{C_{k}}=\frac{1}{K}\sum_{u=1}^{k}S(C_{u}) \tag{13}\]  
The resulting coefficient will vary between \(-1\) and \(1\). A value of \(1\) indicates members of a cluster are very similar within their cluster while further away from members of other clusters, and the reverse applies for negative coefficient values. When substantial cluster overlaps occur, the score decreases, although the relevance of the coefficient can vary between problem domains. The interpretation of the silhouette score can be sufficiently aided by domain expertise. Table 2 presents three simple rules from [30] for the generic interpretation of silhouette scores. \begin{table}
\begin{tabular}{c c} \hline
**Silhouette Value** & **Interpretation** \\
**Range** & **Interpretation** \\ \hline \(\geq 0.5\) & Good evidence for cluster existence in the data. \\  & Some evidence for cluster existence in the data, domain-specific \\ \(\geq 0.25-0.5\) & knowledge, can be brought to bear to support the presence of \\  & the clusters. \\ \(\leq 0.25\) & Scant evidence of cluster reality. \\ \hline \end{tabular}
\end{table}