Get started¶
Biomedical research often uses longitudinal data with repeated measurements of variables across time, which is challenging for standard machine learning algorithms due to intrinsic temporal dependencies.
Scikit-longitudinal (abbreviated Sklong, pronounced /ˌɛs keɪ ˈlɒŋ/ or "Ess-kay-long" and /ˌsaɪ kɪt ˌlɒndʒɪˈtjuːdɪnəl/ or "Sky-kit lon-ji-TOO-din-ul") is a machine learning library for longitudinal classification workflows. It provides two complementary ways to work with repeated-measures data:
- Data preparation: flatten or restructure longitudinal tables into static, tabular representations for standard machine learning workflows.
- Algorithm adaptation: preserve temporal dependencies and train longitudinal-aware estimators that leverage the wave structure directly.
Time series and longitudinal datasets both involve a temporal component, but they are not the same. Time series data typically follows one variable over time, while longitudinal datasets follow multiple variables across the same cohort of individuals at different time points. In Sklong, those time points are treated as waves 123.
Read the official paper
If you would like the architectural view before the hands-on one, start there and then come back to the installation steps below. The library is presented in Scikit-Longitudinal: A Machine Learning Library for Longitudinal Classification in Python, published in the Journal of Open Source Software (JOSS).
Installation¶
Choose the installation method that best suits your workflow.
Operating system and Python support
Use Python 3.10 to 3.13.
Native support is available on macOS and stable Linux distributions such as Ubuntu.
On Windows, use Google Colab or a Linux-based Docker image for now.
Add Scikit-longitudinal to an existing UV-managed project:
Extras work the same way:
You can also pin a specific version if desired:
After adding, run uv sync to materialise the lockfile.
Need UV first?
See the UV installation instructions.
Install the latest release from PyPI:
Extras are available for specialised needs:
pip install "scikit-longitudinal[parallelisation]" # Ray-based parallel workloads
pip install "scikit-longitudinal[dev]" # Docs, testing, linting
You can also pin a specific version if desired:
To install Scikit-longitudinal using Conda, follow these steps:
- Open your terminal or Anaconda Prompt.
- Create a new Conda environment with Python 3.10:
- Activate the environment:
- Install
Scikit-longitudinal:
You can also pin a specific version if desired:
This installs Scikit-longitudinal in your newly created Conda environment.
Launch Jupyter Lab with Sklong in a temporary environment managed by UV:
This uses your default Python (3.10 to 3.13). To pin a specific Python, pass --python <path_or_version>.
- Open a new Colab notebook (Python 3.10–3.13).
- Remove the preinstalled stock
scikit-learn(Sklong relies on thescikit-lexicographical-treesfork which ships its ownsklearnpackage):
- Install
Sklong(this pulls inscikit-lexicographical-treesautomatically):
Info
Support for Marimo is incoming. If you are interested in contributing to this feature, please submit a pull request.
If you are setting up Sklong inside a project, ensure your dependency manager prefers scikit-lexicographical-trees instead of scikit-learn and declare scikit-longitudinal in your project metadata.
Project setup with PDM
Add the dependency and exclude scikit-learn in pyproject.toml:
[project]
dependencies = [
"scikit-longitudinal",
]
[tool.pdm.resolution]
excludes = ["scikit-learn"]
Install dependencies:
Project setup with UV
Declare the dependency and override the incompatible wheel:
[project]
dependencies = [
"scikit-longitudinal",
]
[tool.uv]
package = true
override-dependencies = [
"scikit-learn ; sys_platform == 'never'",
]
Then sync your environment:
Have trouble installing Sklong?
Known issues and workarounds live in the installation and troubleshooting section of the Developers guide.
-
Kelloway, E.K. and Francis, L., 2012. Longitudinal research and data analysis. In Research methods in occupational health psychology (pp. 374-394). Routledge. ↩
-
Ribeiro, C. and Freitas, A.A., 2019. A mini-survey of supervised machine learning approaches for coping with ageing-related longitudinal datasets. In 3rd Workshop on AI for Aging, Rehabilitation and Independent Assisted Living (ARIAL), held as part of IJCAI-2019. ↩
-
Ribeiro, C. and Freitas, A.A., 2024. A lexicographic optimisation approach to promote more recent features on longitudinal decision-tree-based classifiers: applications to the English Longitudinal Study of Ageing. Artificial Intelligence Review, 57(4), p.84. ↩