# Clustering of Heart Failure Phenotypes in Johannesburg Using Unsupervised Machine Learning
## 2 Methods
### Cluster Analysis  
Clustering is a form of unsupervised machine learning where data are categorised into groups based on similarities within data points in each group. Before clustering the heart failure data, the feature \"mortality\" that characterises the vitality status of each patient upon discharge (dead or alive) from the dataset was removed. The rationale for removing the outcome \"mortality\" lies behind the premise that unsupervised machine learning clusters unlabelled data without a clearly defined outcome. As a result, mortality did not influence the creation of clusters. Clustering was conducted using a dataset with and without the LVEF. This was carried out to evaluate the true importance of the LVEF in categorising heart failure patients.  
Seven clustering algorithms were used to cluster heart failure patients: a partitioning method (K-prototype and K-means), a hierarchical method (agglomerative and Balanced Iterative Reducing and Clustering Hierarchies--BIRCH), density-based (Ordering Points To Identify the Clustering Structure--OPTICS and density-based spatial clustering of applications with noise--DBSCAN), and a model-based clustering method, a Gaussian mixture model.  
Distance-based algorithms use K-means, K-modes, or both to estimate the distance between data points. Agglomerative clustering, also referred to a \"bottom-up\" approach, initially treats each observation (patient) as a single cluster. The algorithm then successively agglomerates pairs of clusters until a single cluster is formed.  
The DBSCAN algorithm groups data points close to each other based on the density of data points in a particular region, marking outliers as points in a low-density region. The Gaussian mixture model uses multiple Gaussian distributions to identify various clusters, with the assumption that each modal distribution represents a particular structure.  
Using the dataset that includes the LVEF, agglomerative clustering was chosen as the best algorithm for clustering heart failure patients since it achieved the highest silhouette score. Using the ward linkage method, the agglomerative clustering algorithm identified three clusters with a silhouette score of 0.72 (Table 1). A silhouette score measures the goodness of fit of clusters by measuring the distance between points within a cluster and spacing between each cluster. This score ranges between \(-\)1 and +1, where the best score, +1, suggests that clusters are far from each other and \(-\)1 infers that clusters are poorly describing patterns in the dataset. A dendrogram was also plotted to represent the clusters visually. Shapley additive explanations (SHAP) was used to identify and rank features that played a prominent role in the segmentation of the heart failure cohort into three clusters using the agglomerative clustering algorithm. Both the DBSCAN and OPTICS algorithms were unsuccessful in clustering the data.  
After removing the LVEF from the dataset, the Gaussian mixture model had the highest silhouette score of 0.30. This silhouette score corresponded to three clusters. These clusters were subsequently compared with the LVEF categories (HFrEF, HFmEF, and HFpEF). The SHAP values for the Gaussian mixture model were also generated.