PHOTONAI—A Python API for rapid machine learning model development

Ramona Leenings, Nils R. Winter, Lucas Plagwitz, Vincent Holstein, Jan Ernsting, Kelvin Sarink, L. Fisch, Jakob Steenweg, Leon Kleine-Vennekate, Julian Gebker, Daniel Emden, Dominik Grotegerd, Nils Opel, Benjamin Risse, Xiaoyi Jiang, Udo Dannlowski, Tim Hahn

Abstract

PHOTONAI is a high-level Python API designed to simplify and accelerate machine learning model development. It functions as a unifying framework allowing the user to easily access and combine algorithms from different toolboxes into custom algorithm sequences. It is especially designed to support the iterative model development process and automates the repetitive training, hyperparameter optimization and evaluation tasks. Importantly, the workflow ensures unbiased performance estimates while still allowing the user to fully customize the machine learning analysis. PHOTONAI extends existing solutions with a novel pipeline implementation supporting more complex data streams, feature combinations, and algorithm selection. Metrics and results can be conveniently visualized using the PHOTONAI Explorer and predictive models are shareable in a standardized format for further external validation or application. A growing add-on ecosystem allows researchers to offer data modality specific algorithms to the community and enhance machine learning in the areas of the life sciences. Its practical utility is demonstrated on an exemplary medical machine learning problem, achieving a state-of-the-art solution in few lines of code.

Introduction

Building a robust machine learning (ML) pipeline is often a fragmented, manual process. Researchers typically juggle multiple libraries—such as scikit-learn for preprocessing, imbalanced-learn for sampling, and various Bayesian optimizers—each with its own syntax. This manual integration is not only tedious but also poses a significant risk of data leakage, where information from the test set inadvertently influences the training process, leading to over-optimistic results that fail in real-world applications.

Furthermore, standard pipeline implementations are often too rigid to handle complex scenarios like automated algorithm selection, parallel data streams, or mid-pipeline target vector modifications (e.g., for oversampling). PHOTONAI addresses these challenges by acting as a mediator between existing toolboxes, built on top of the familiar scikit-learn API.

Methods and Architecture

PHOTONAI introduces several novel components to orchestrate the ML workflow while strictly enforcing nested cross-validation to ensure unbiased performance estimates.

The architectural design of PHOTONAI, illustrating the relationships between the Hyperpipe, Pipeline, and Hyperparameter Optimizer components.

Key architectural elements include:

  • Hyperpipe: The central management class that orchestrates the entire workflow, including nested cross-validation, logging, and performance ranking.
  • The Switch Element: An "OR-operation" for pipelines. It allows the user to define multiple candidate algorithms for a single slot, treating the choice of algorithm itself as a hyperparameter to be optimized.
  • The Stack Element: An "AND-operation" that enables parallel data streams. It can horizontally concatenate features from different processing branches or create complex ensembles.
  • The Branch Element: Allows for nested sub-pipelines, which is particularly useful for multi-modal data processing.
Logic of the Stack element, showing parallel data streams being processed by PipelineElements and merged via an AND operation.

By enforcing a strict separation between the "inner" loop (used for tuning) and the "outer" loop (used for final evaluation), PHOTONAI makes common errors, such as performing feature selection on the entire dataset before cross-validation, nearly impossible.

Evaluation: Heart Failure Prediction

The authors demonstrated the API's utility using a Heart Failure Clinical Records dataset, containing 13 clinical features from 299 patients. This "small-n" medical dataset is characterized by significant class imbalance, making it an ideal test case for PHOTONAI’s automated sampling and validation features.

Key Results

  • Performance Boost: PHOTONAI achieved an F1-score of 0.746, significantly outperforming the previous state-of-the-art benchmark of 0.714.
  • Efficiency: This result was achieved with minimal code, automating a process that would typically require hundreds of lines of boilerplate for manual nested cross-validation and class balancing.
  • Insightful Visualization: Using the "PHOTONAI Explorer," the authors visualized the hyperparameter search space, finding that random under-sampling generally provided better performance for this specific problem than more complex over-sampling techniques.

Discussion and Future Work

PHOTONAI treats algorithm selection as an optimization problem and introduces the .photon file format to facilitate the sharing of entire optimized pipeline architectures. While the framework requires a one-time registration for custom algorithms and is currently less optimized for extremely bespoke deep learning architectures, its extensibility is a core strength.

Future directions include expanding the add-on ecosystem for life sciences (e.g., neuroimaging and graph-based data) and automating ensemble generation, where the best-performing models from the optimization process are automatically combined to further boost accuracy.

Summary updated

BibTeX
@inproceedings{leenings2021photonaia,
  author = {Ramona Leenings and Nils R. Winter and Lucas Plagwitz and Vincent Holstein and Jan Ernsting and Kelvin Sarink and L. Fisch and Jakob Steenweg and Leon Kleine-Vennekate and Julian Gebker and Daniel Emden and Dominik Grotegerd and Nils Opel and Benjamin Risse and Xiaoyi Jiang and Udo Dannlowski and Tim Hahn},
  title = {{PHOTONAI—A Python API for rapid machine learning model development}},
  booktitle = {PLoS},
  year = {2021},
  doi = {10.1371/journal.pone.0254062},
}
Figure