Skip to main content

DNAttend - ML framework for predicting patient non-attendance

Train, test and validate a CatBoost Classifier for predicting patient non-attendance (DNA)

status: experimental build: status

Table of contents

Installation

Installation is possible via pip as shown below.

Unix/macOS

python3 -m pip install dnattend

Windows

py -m pip install dnattend

Install within a Virtual Environment (optional)

Unix/macOS
python -m venv dnattend
source dnattend/bin/activate
python3 -m pip install dnattend
Windows
py -m venv dnattend
dnattend/Scripts/Activate.ps1
py -m pip install dnattend

If running scripts is disabled on your system then run the following command before activating your environment.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Worklow

workflow
Overview of DNAttend workflow

Refer to the additional documentation for further details of the underlying classifier framework.

Usage

The following sections document the built-in example workflow provided. It is recommended that users follow this workflow to verify proper installation.

Generate Example Data

The simulate sub-command generates suitably formatted input data for testing functionality. It also writes an example config file in YAML format. Both of these output files can serve as templates for building real-world models.

dnattend simulate --config config.yaml DNAttend-example.csv

Train Model

DNAttend trains two models independently; a baseline logistic regression model and a CatBoost model. The baseline model is simple model that acts as reference to assess performance improvements of CatBoost. Refer to the additional documentation for further details of the model workflow.

dnattend train config.yaml

Evaluate Model

Following initial training, the dnattend test command can be used to assess performance of both the logistic regression and CatBoost models against the hold-out testing data set. Refer to the additional documentation for example output visualisation and performance metrics.

dnattend test config.yaml

Refit Model with All Data

The previous steps have trained two models: a baseline logistic regression model and a more advanced CatBoost. Following parameterisation and assessment of model performance, a final model can be retrained using the entire data set. The user may build a logistic regression or CatBoost model depending on the performance metrics. This choice must be specified by the user in the finalModel: option of the configuration file.

dnattend retrain config.yaml

Generate Predictions

The trained model is now ready to be used. Predictions should be made with the predict module - this ensures the tuned decision threshold is correctly applied when assigning classes. The output of predict includes the decision class (i.e.Attend and DNA) and the underlying probabilities of theses classes. The output results of this example can be found here

dnattend predict --verify DNAttend-example.csv catboost-final.pkl > FinalPredictions.csv

Note: the --verify flag is only required when running the example workflow (see below).

Example Workflow Verification

Following initial installation, it is recommended that users run the example workflow, as described, to verify that the pipeline is functioning as expected. The --verify flag of dnattend predict, as shown above, will check the results against the expected output and notify the user if the output matches or not.

Configuration

DNAttend utilises a single configuration file, in YAML, which documents all model parameter and ensure reproducibility of the analysis. The dnattend simulate command writes an example documented configuration file that the user can use as a template. A copy of this file is shown below and available to download here.

input: DNAttend-example.csv    # Path to input data (Mandatory).
target: status                 # Column name of target (Mandatory).
DNAclass: 1                    # Value of target corresponding to DNA.
out: .                         # Output directory to save results.
finalModel: catboost           # Method to train final model (catboost or logistic).
catCols:                       # Column names of categorical features.
    - day
    - priority
    - speciality
    - consultationMedia
    - site
boolCols:                      # Column names of boolean features.
    - firstAppointment
numericCols:                   # Column names of numeric features.
    - age
train_size: 0.7                # Proportion of data for training.
test_size: 0.15                # Proportion of data for testing.
val_size: 0.15                 # Proportion of data for validation.
tuneThresholdBy: f1            # Metric to tune decision threshold (f1 or roc).
cvFolds: 5                     # Hyper-tuning cross-validations.
catboostIterations: 100        # Hyper-tuning CatBoost iterations.
hypertuneIterations: 5         # Hyper-tuning parameter samples.
evalIterations: 10_000         # Upper-limit over-fit iterations.
earlyStoppingRounds: 10        # Over-fit detection early stopping rounds.
seed: 42                       # Seed to ensure workflow reproducibility.

Further Documentation

Refer to the additional documentation for further technical details of the modeling framework and visualisations from the example data set.

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

If you have any other questions please contact the author, Stephen Richer.

Metadata

Release files for dnattend 0.2.3

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

Source distribution (sdist)

Source distribution for dnattend 0.2.3
File Size Uploaded Provenance Actions
dnattend-0.2.3.tar.gz 18.1 kB Without provenance Details for dnattend-0.2.3.tar.gz

Built distribution (wheel)

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

Total release size: 35.9 kB

Release files / dnattend-0.2.3.tar.gz

Download URL dnattend-0.2.3.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5f5eb1cb9c2948f9a9977823a8954bf5f36fbe01c70c8084c512666ef2686c35
BLAKE2b-256 checksum
How to use checksums
5af131460878ea99d9c1c5259238e54824675427eed15e1fe89ddf744218239d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Release files / dnattend-0.2.3-py3-none-any.whl

Download URL dnattend-0.2.3-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
46c6fca7b5d0745500a2cd9ca7c7a6423e1272810ea922e3b20548ab4d96c276
BLAKE2b-256 checksum
How to use checksums
726afa27b4acd0c62980d21cfb41fe1badfc424ce4b8dffbfc30c090e250c64f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.7

Security for dnattend 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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