Unsupervised machine learning predicts future sexual behaviour and sexually transmitted infections among HIV-positive men who have sex with men

PLoS Comput Biol. 2022 Oct 27;18(10):e1010559. doi: 10.1371/journal.pcbi.1010559. eCollection 2022 Oct.


Machine learning is increasingly introduced into medical fields, yet there is limited evidence for its benefit over more commonly used statistical methods in epidemiological studies. We introduce an unsupervised machine learning framework for longitudinal features and evaluate it using sexual behaviour data from the last 20 years from over 3'700 participants in the Swiss HIV Cohort Study (SHCS). We use hierarchical clustering to find subgroups of men who have sex with men in the SHCS with similar sexual behaviour up to May 2017, and apply regression to test whether these clusters enhance predictions of sexual behaviour or sexually transmitted diseases (STIs) after May 2017 beyond what can be predicted with conventional parameters. We find that behavioural clusters enhance model performance according to likelihood ratio test, Akaike information criterion and area under the receiver operator characteristic curve for all outcomes studied, and according to Bayesian information criterion for five out of ten outcomes, with particularly good performance for predicting future sexual behaviour and recurrent STIs. We thus assess a methodology that can be used as an alternative means for creating exposure categories from longitudinal data in epidemiological models, and can contribute to the understanding of time-varying risk factors.

Publication types

  • Research Support, Non-U.S. Gov't

MeSH terms

  • Bayes Theorem
  • Cohort Studies
  • HIV Infections* / epidemiology
  • Homosexuality, Male
  • Humans
  • Male
  • Sexual Behavior
  • Sexual and Gender Minorities*
  • Sexually Transmitted Diseases* / epidemiology
  • Unsupervised Machine Learning

Grant support

This study has been financed within the framework of the Swiss HIV Cohort Study, supported by the Swiss National Science Foundation (grant 201369), by the SNF project grant 324730_179567, and by the SHCS research foundation (project number 823). RDK and SB were supported by the Swiss National Science Foundation (grant BSSGI0_155851). The funders had no role in study design, data collection and analysis, decision to publish, or preparation of the manuscript.