K-means Clustering & Data Mining in Precision Medicine

K-means Clustering & Data Mining in Precision Medicine

Sharing Knowledge

K-means Clustering & Data Mining in Precision Medicine

SM
Sara McCarney, Senior Software Engineer
8 min read · Updated February 2024

Key Takeaways

  • K-means clustering is an unsupervised machine learning algorithm that groups data points into K clusters by iteratively minimising within-cluster variance - one of the fastest and most widely used clustering methods in bioinformatics
  • Applied to TCGA STAD RNA-seq data, K-means clustering of CTNNB1 and NOTCH1 expression identified two patient clusters with statistically significantly different overall survival (log-rank p = 0.011)
  • This demonstrates how K-means clustering can identify molecular subtypes in precision medicine - uncovering prognostic signals from gene expression data that support patient stratification strategies

K-means clustering is one of several available clustering algorithms and can be traced back to Hugo Steinhaus in 1956. K-means is a non-supervised machine learning algorithm which aims to organise data points into K clusters of equal variance. It is a centroid-based technique and one of the fastest clustering algorithms available.

Unsupervised Machine Learning

Machine learning algorithms may be categorised into two general groups based on their learning approach: supervised and unsupervised. Supervised learning requires labelled data as input, with the model attempting to learn how the data corresponds to its label. XGBoost and decision tree models are examples of supervised machine learning.

Unsupervised learning requires no labelling of the input data. Instead, the model groups or detects similarities, patterns or anomalies within unlabelled data. K-means is one such unsupervised method that aims to group similar data points in clusters. t-SNE, a dimensionality reduction algorithm, is another example of unsupervised learning frequently used alongside K-means in precision medicine workflows.

Algorithm Summary

Animated example of K-means clustering showing centroids iterating through assignment and update steps until convergence

An example of K-means clustering by Kevin Arvai where K centroids iterate through the assignment and update steps until convergence.

  1. Initialise centroids
  2. For each sample: assign it to its closest cluster K based on Euclidean distance
  3. For each cluster: recalculate the centroid based on the mean of samples in the cluster
  4. Repeat steps 2-3 until a stopping criterion is fulfilled
  5. Determine the variance of each cluster and sum (SSE)
  6. Repeat steps 1-5 with different centroid initialisations n_init times
  7. The initialisation with the lowest SSE is selected as the final result

How it Works - More Detail

Before the algorithm starts, the number of clusters K should be specified by the user. The K-means algorithm then initialises the positions of the K cluster centroids. These centroid positions can have random initialisation, or a special algorithm can be used to speed up convergence. The K-means++ algorithm is one such approach - and is now the default initialisation in scikit-learn 1.0 and later, significantly improving both speed and result quality.

Following initialisation, each sample in the dataset is assigned to its closest centroid based on Euclidean distance. Once all data points are assigned, cluster centroids are recomputed by taking the mean of the cluster's data points. This process repeats until the stopping criterion is met.

Over the set of samples, this translates to minimising the inertia or within-cluster sum-of-squares (SSE):

K-means clustering SSE equation where n is the number of samples, mu is the centroid mean, and C is the number of centroids

Where n is the number of samples, μ is the centroid mean, and C is the number of centroids.

Once the SSE is collected, the process can be terminated - but it is recommended to restart several times with different centroid initialisations and select the best-performing model, as K-means can fall into local minima.

Advantages & Limitations of K-means Clustering

K-means is the most commonly used method in data analytics, largely due to its inexpensive compute, ease of implementation, and ability to scale well with large data. It will always converge. K-means clustering can also be used as a pre or post-processing step for other machine learning algorithms - for example, PCA can be used prior to K-means as a feature extraction step to reveal clusters.

However, it is worth considering that other methods might be better suited to your dataset. Examples include hierarchical clustering or expectation maximisation techniques. The table below outlines the key limitations and how they can be addressed:

Limitation How to resolve it
Number of clusters must be chosen manually Find an optimal number of clusters using Elbow and Silhouette Analysis
Outliers can have strong influence on results Remove outliers before clustering
Initial centroid positions have strong influence on results Restart clustering multiple times to find optimal SSE; use K-means++ initialisation (default in scikit-learn 1.0+)
Does not cluster well with clusters of varying sizes and densities Consider using Gaussian mixture models or other density-based methods

K-means Clustering as Data Mining

Clustering techniques are commonly adopted by data science teams across a wide range of domains. They help us gain insights into how the features in our data relate to each other. Gaining new insights into existing data is known as data mining. Using the clustering result, data mining can uncover patterns and trends existing in the data.

Data mining can be used across many industries including fraud detection. In precision medicine, data mining can help determine which patients will respond to treatments - making K-means clustering a natural fit for patient stratification workflows and for uncovering molecular subtypes in complex datasets. It is also used in AI high content screening to group compounds with similar mechanisms of action, and in multi-omics integration to reveal structure across combined datasets.

K-means Clustering in Precision Medicine: Gastric Cancer Survival Analysis

K-means clustering assigns data points to one of two clusters on a 2D plot showing separation by gene expression values

K-means assigns data points to one of two clusters on a 2D plot - each point represents a patient sample, coloured by cluster assignment.

Precision medicine aims to find alternatives to a one-size-fits-all approach to healthcare by dividing target groups into smaller semantic sub-groups, where treatment efficacy and patient outcomes may vary significantly. Going beyond traditional subtyping approaches, unsupervised machine learning techniques can identify subgroups of patients based on their molecular data.

In gastric adenocarcinoma, there is increasing evidence to suggest that dysregulated stem cell biology is strongly associated with disease recurrence and treatment resistance. A recent study characterised the mRNA expression patterns of stem-like genes in gastric cancer samples. We have further investigated two of the key genes reported in this study - CTNNB1 and NOTCH1 - using publicly available data from The Cancer Genome Atlas (TCGA).

Using the K-means algorithm on the TCGA STAD RNA-seq dataset, each patient was assigned to a cluster based on their CTNNB1 and NOTCH1 expression. Comparing the two clusters on a Kaplan-Meier curve, we observed a statistically significant difference in overall survival between clusters (log-rank: p = 0.011).

Kaplan-Meier survival curve showing statistically significant difference in overall survival between two K-means clusters of gastric cancer patients defined by CTNNB1 and NOTCH1 RNA-seq expression, log-rank p = 0.011

Kaplan-Meier curve showing survival analysis of gene clusters identified by K-means clustering of CTNNB1 and NOTCH1 expression on the TCGA STAD RNA-seq dataset. Log-rank: p = 0.011.

This finding builds upon the study by Jafari et al. and supports other findings in the literature. It demonstrates the utility of unsupervised clustering techniques such as K-means in precision medicine - the clusters identify molecular subtypes that yield prognostic value (data mining). Once identified, these molecular subtypes require further biomarker validation before they can inform clinical decisions. See also how similar approaches are applied in our AI single-cell analysis use case, where clustering of cell populations reveals biologically meaningful immune subsets.

Patient Stratification

See how K-means-derived molecular subtypes feed into patient stratification strategies that guide biomarker-driven clinical trial design.

Learn more

Related Reading

Talk to our team

Sonrai acts as an extension of your team, combining scientific expertise, transparent and reproducible analysis, and a governed research environment to generate decision-ready evidence that can be revisited, reproduced, and built upon throughout the life of a programme.

Book a demo
Related Posts