Scikit-mobility: a Python library for the analysis, generation and risk assessment of mobility data

Luca Pappalardo, Filippo Simini, Gianni Barlacchi, Roberto Pellungrini

Abstract

The last decade has witnessed the emergence of massive mobility data sets, such as tracks generated by GPS devices, call detail records, and geo-tagged posts from social media platforms. These data sets have fostered a vast scientific production on various applications of mobility analysis, ranging from computational epidemiology to urban planning and transportation engineering. A strand of literature addresses data cleaning issues related to raw spatiotemporal trajectories, while the second line of research focuses on discovering the statistical "laws" that govern human movements. A significant effort has also been put on designing algorithms to generate synthetic trajectories able to reproduce, realistically, the laws of human mobility. Last but not least, a line of research addresses the crucial problem of privacy, proposing techniques to perform the re-identification of individuals in a database. A view on state of the art cannot avoid noticing that there is no statistical software that can support scientists and practitioners with all the aspects mentioned above of mobility data analysis. In this paper, we propose scikit-mobility, a Python library that has the ambition of providing an environment to reproduce existing research, analyze mobility data, and simulate human mobility habits. scikit-mobility is efficient and easy to use as it extends pandas, a popular Python library for data analysis. Moreover, scikit-mobility provides the user with many functionalities, from visualizing trajectories to generating synthetic data, from analyzing statistical patterns to assessing the privacy risk related to the analysis of mobility data sets.

Introduction

The proliferation of mobility data from GPS, call detail records (CDRs), and social media has opened new frontiers in urban planning and epidemiology. However, the research landscape has historically been fragmented, with scientists often forced to switch between disparate tools or custom scripts to clean data, model movement laws, generate synthetic trajectories, and assess privacy risks. scikit-mobility fills this gap by providing a unified, comprehensive Python library designed as a "one-stop-shop" for human mobility analysis.

Methods and Data Structures

Built on top of the standard Python data science stack (pandas, numpy, and geopandas), scikit-mobility introduces two fundamental data structures that streamline the analysis pipeline:

  1. TrajDataFrame: Designed for individual-level trajectory data, it requires four mandatory columns: latitude, longitude, timestamp, and a user identifier (uid).
The structure of a TrajDataFrame, showing the required columns for latitude, longitude, timestamp, and object identifier.
  1. FlowDataFrame: Designed for collective-level data, representing aggregated movements (flows) between geographic regions or tiles.

Functional Pillars

The library is organized into five core functional modules:

  • Preprocessing: Tools for noise filtering (e.g., max speed filters), stop detection, and trajectory compression.
  • Visualization: Interactive map plotting powered by folium and matplotlib.
  • Measures: Implementation of standard mobility metrics like Radius of Gyration and entropy.
  • Generative Models: Includes individual models like the Exploration and Preferential Return (EPR) model and collective models like Gravity and Radiation models.
  • Privacy Assessment: A unique module that simulates re-identification attacks to quantify privacy risks.
A summary of common preprocessing methods available in the library, including clustering, compression, and stop detection.

Key Insights and Results

scikit-mobility distinguishes itself by treating privacy as a first-class citizen, reflecting modern legal requirements like the GDPR. By extending pandas, the library ensures that all standard data manipulation techniques work out of the box, significantly lowering the learning curve for data scientists.

Comparative analysis shows that while existing libraries like bandicoot or movingpandas focus on specific data types or geometric operations, scikit-mobility is the only package that covers the entire workflow—from preprocessing and plotting to generative modeling and privacy risk assessment. The authors demonstrate that complex tasks, such as fitting a singly-constrained gravity model to commuting data, can be achieved in fewer than ten lines of code.

Limitations and Future Work

As a pandas-based library, scikit-mobility is currently memory-bound, requiring datasets to fit within RAM. This limits its direct application to "terabyte-scale" data without integration with tools like dask. Future updates aim to include modules for next-location prediction using machine learning, map matching for road networks, and improved computational efficiency through parallel processing.

Summary updated

Abstract

The last decade has witnessed the emergence of massive mobility data sets, such as tracks generated by GPS devices, call detail records, and geo-tagged posts from social media platforms. These data sets have fostered a vast scientific production on various applications of mobility analysis, ranging from computational epidemiology to urban planning and transportation engineering. A strand of literature addresses data cleaning issues related to raw spatiotemporal trajectories, while the second line of research focuses on discovering the statistical "laws" that govern human movements. A significant effort has also been put on designing algorithms to generate synthetic trajectories able to reproduce, realistically, the laws of human mobility. Last but not least, a line of research addresses the crucial problem of privacy, proposing techniques to perform the re-identification of individuals in a database. A view on state of the art cannot avoid noticing that there is no statistical software that can support scientists and practitioners with all the aspects mentioned above of mobility data analysis. In this paper, we propose scikit-mobility, a Python library that has the ambition of providing an environment to reproduce existing research, analyze mobility data, and simulate human mobility habits. scikit-mobility is efficient and easy to use as it extends pandas, a popular Python library for data analysis. Moreover, scikit-mobility provides the user with many functionalities, from visualizing trajectories to generating synthetic data, from analyzing statistical patterns to assessing the privacy risk related to the analysis of mobility data sets.
BibTeX
@article{pappalardo2019scikit,
  author = {Luca Pappalardo and Filippo Simini and Gianni Barlacchi and Roberto Pellungrini},
  title = {{Scikit-mobility: a Python library for the analysis, generation and risk assessment of mobility data}},
  journal = {J. Stat. Softw.},
  year = {2019},
}
Figure