Skip to main content

slingpy

Python version Library version

The slingpy python package provides starter code for structured, reproducible and maintainable machine learning projects. slingpy aims to be maximally extensible while maintaining sensible defaults. It is agnostic in terms of modelling backend (e.g., supporting scikit-learn, torch and tensorflow) and suitable for both production and research-grade machine learning projects.

slingpy contains utilities for standard model evaluation workflows, such as nested cross validation, model serialisation, dataset handling, managing high performance computing (HPC) interfaces such as slurm, and by default writes all experiment artefacts to disk.

Install

pip install slingpy

Use

A minimal slingpy project consists of a base application that defines your basic modelling workflow.

import slingpy as sp
from typing import AnyStr, Dict, List
from sklearn.linear_model import LogisticRegression


class MyApplication(sp.AbstractBaseApplication):
    def __init__(self, output_directory: AnyStr = "",
                 schedule_on_slurm: bool = False,
                 split_index_outer: int = 0,
                 split_index_inner: int = 0,
                 num_splits_outer: int = 5,
                 num_splits_inner: int = 5):
        super().__init__(
            output_directory=output_directory,
            schedule_on_slurm=schedule_on_slurm,
            split_index_outer=split_index_outer,
            split_index_inner=split_index_inner,
            num_splits_outer=num_splits_outer,
            num_splits_inner=num_splits_inner
        )

    def get_metrics(self, set_name: AnyStr) -> List[sp.AbstractMetric]:
        return [
            sp.metrics.AreaUnderTheCurve()
        ]

    def load_data(self) -> Dict[AnyStr, sp.AbstractDataSource]:
        data_source_x, data_source_y = sp.datasets.Iris.load_data(self.output_directory)

        stratifier = sp.StratifiedSplit()
        rest_indices, training_indices = stratifier.split(data_source_y, test_set_fraction=0.6,
                                                          split_index=self.split_index_inner)
        validation_indices, test_indices = stratifier.split(data_source_y.subset(rest_indices), test_set_fraction=0.5,
                                                            split_index=self.split_index_outer)

        return {
            "training_set_x": data_source_x.subset(training_indices),
            "training_set_y": data_source_y.subset(training_indices),
            "validation_set_x": data_source_x.subset(validation_indices),
            "validation_set_y": data_source_y.subset(validation_indices),
            "test_set_x": data_source_x.subset(test_indices),
            "test_set_y": data_source_y.subset(test_indices)
        }

    def train_model(self) -> sp.AbstractBaseModel:
        model = sp.SklearnModel(LogisticRegression())
        model.fit(self.datasets.training_set_x, self.datasets.training_set_y)
        return model


if __name__ == "__main__":
    app = sp.instantiate_from_command_line(MyApplication)
    app._run()

Your new app can then be executed locally from the command line using:

python /project_path/my_application.py

slingpy also enables execution of your project on a remote HPC cluster, e.g. via slurm, by using:

python /project_path/my_application.py --do_schedule_on_slurm

Application parameters are automatically parsed from the command line, e.g.:

python /project_path/my_application.py --output_directory=/path/to/output/dir

Development

The slingpy codebase is formatted with Black and Import Sort to ensure consistant code formatting. These are run through pre-commit. If making code changes to slingpy, install the development dependencies and pre-commit git hook with:

pip install -r requirements-dev.txt
pre-commit install

License

License

Authors

Patrick Schwab, GlaxoSmithKline plc
Arash Mehrjou, GlaxoSmithKline plc
Andrew Jesson, University of Oxford
Ashkan Soleymani, MIT

Acknowledgements

PS and AM are employees and shareholders of GlaxoSmithKline plc.

Release files for slingpy 0.2.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slingpy 0.2.12
File Size Uploaded
slingpy-0.2.12.tar.gz 54.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for slingpy 0.2.12
File Interpreter ABI Platform
slingpy-0.2.12-py3-none-any.whl Python 3 none any Details

Total release size: 183.9 kB

Release files / slingpy-0.2.12.tar.gz

Download URL slingpy-0.2.12.tar.gz
Size 54.8 kB
Tags Source
SHA-256 checksum
How to use checksums
94b1df8d197b2867dbbd6fdc44ca9f2a300fde32d20272b2a0082309722227d9
BLAKE2b-256 checksum
How to use checksums
16af0dc74c5f13ada78fd91f7ee4d7b10dce63da26f2dc32131aa819fc568d45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.7

Release files / slingpy-0.2.12-py3-none-any.whl

Download URL slingpy-0.2.12-py3-none-any.whl
Size 129.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45da22e26db8321726de495c9ffbb33316a1a8258f543ffb4536ab71dfbf8728
BLAKE2b-256 checksum
How to use checksums
3de69d8ebcb4cd8602a9422b3a944bb848ce92bc1cf61bb7d75dd8fc63cda42c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.7

Release history Release notifications | RSS feed

This release

0.2.12 This release

2 release files

0.2.10

2 release files

0.2.9

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page