Package: dnattend
DNAttend - ML framework for predicting patient non-attendanceTrain, test and validate a CatBoost Classifier for predicting patient non-attendance (DNA)Table of contentsInstallationWorkflowUsageGenerate Example DataTrain ModelEvaluate ModelRefit Model with All DataGenerate PredictionsExample Data VerificationConfigurationFurther DocumentationContributingLicenseContactInstallationInstallation is possible viapipas shown below.Unix/macOSpython3-mpipinstalldnattendWindowspy-mpipinstalldnattendInstall within a Virtual Environment (optional)Unix/macOSpython-mvenvdnattendsourcednattend/bin/activate
python3-mpipinstalldnattendWindowspy-mvenvdnattend
dnattend/Scripts/Activate.ps1
py-mpipinstalldnattendIf running scripts is disabled on your system then run the following command before activating your environment.Set-ExecutionPolicy-ExecutionPolicyRemoteSigned-ScopeCurrentUserWorklowOverview of DNAttend workflowRefer to theadditional documentationfor further details of the underlying classifier framework.UsageThe following sections document the built-in example workflow provided.
It is recommended that users follow this workflow to verify proper installation.Generate Example DataThesimulatesub-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.dnattendsimulate--configconfig.yamlDNAttend-example.csvTrain ModelDNAttend 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 theadditional documentationfor further details of the model workflow.dnattendtrainconfig.yamlEvaluate ModelFollowing initial training, thednattend testcommand can be used to assess performance of both the logistic regression and CatBoost models against the hold-out testing data set.
Refer to theadditional documentationfor example output visualisation and performance metrics.dnattendtestconfig.yamlRefit Model with All DataThe 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 thefinalModel:option of the configuration file.dnattendretrainconfig.yamlGenerate PredictionsThe trained model is now ready to be used.
Predictions should be made with thepredictmodule - this ensures the tuned decision threshold is correctly applied when assigning classes.
The output ofpredictincludes the decision class (i.e.AttendandDNA) and the underlying probabilities of theses classes.
The output results of this example can be foundherednattendpredict--verifyDNAttend-example.csvcatboost-final.pkl>FinalPredictions.csvNote: the--verifyflag is only required when running the example workflow (see below).Example Workflow VerificationFollowing initial installation, it is recommended that users run the example workflow, as described, to verify that the pipeline is functioning as expected.
The--verifyflag ofdnattend predict, as shown above, will check the results against the expected output and notify the user if the output matches or not.ConfigurationDNAttend utilises a single configuration file, in YAML, which documents all model parameter and ensure reproducibility of the analysis.
Thednattend simulatecommand 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 downloadhere.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-siteboolCols:# Column names of boolean features.-firstAppointmentnumericCols:# Column names of numeric features.-agetrain_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 DocumentationRefer to theadditional documentationfor further technical details of the modeling framework and visualisations from the example data set.ContributingContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make aregreatly appreciated.Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull RequestLicenseDistributed under the MIT License.SeeLICENSEfor more information.ContactIf you have any other questions please contact the author,Stephen Richer.