This demo shows how to train and interpret a machine learning classifier using clinical measurements from heart failure patients. The tutorial covers data splitting, model training with cross-validation, evaluation metrics, and feature importance analysis with SHAP.
The analysis runs inside a container, which bundles all the required software so that it works the same way on any machine and can be easily transferred to a sensitive data computing environment.
| File | Description |
|---|---|
VISU_tutorial.ipynb |
Jupyter notebook for computing results |
Dockerfile |
Defines the container environment |
requirements.txt |
Python packages installed in the container |
- Docker installed and running (Docker Desktop, Docker Compose or Docker Engine)
- At least a few GB of free disk space to build the Docker image (5.27 GB) and extract it (1.26 GB)
- For Step 3 (sensitive data / VISU environment): an active research permit, computing envieonment order and an SSH key registered at https://u.oulu.fi/sshkeys
Download the heart failure dataset from the UCI Machine Learning Repository:
https://archive.ics.uci.edu/dataset/519/heart+failure+clinical+records
Extract the zip file. Move the file heart_failure_clinical_records_dataset.csv to the data folder in the repository.
Make sure that your user has access to the directory (Properties → Permissions)
Make sure Docker is running and build the image from the project folder:
docker build -t visu-demo-image:jupyter-notebook .This downloads the jupyter/scipy-notebook base environment and installs all required packages. It may take a few minutes the first time.
The image is named visu-demo-image and tagged jupyter-notebook.
Start JupyterLab using the below command. You can replace ./data with the folder where you saved the dataset if necessary.
docker run --rm -p 8888:8888 -v ./data:/code/data visu-demo-image:jupyter-notebookOpen the URL printed in the terminal (starting with http://127.0.0.1:8888/...) in your browser, then open VISU_tutorial.ipynb.
You can go through the notebook by running the individual code cells one after another or all at once.
Using
-v ./data:/code/datamakes your local data folder available inside the container at the path/code/data. The dataset file should be at/code/data/heart_failure_clinical_records_dataset.csvinside the container.
The printed URL address contains an access token (character sequence after
?token=parameter). JupyterLab uses this for user identification. No login is needed when the full URL address is used.
On VISU, and other research platforms that use Apptainer, the Docker image is first converted to an Apptainer image (.sif file).
Sensitive data is not included in the image.
It is provided to VISU staff by University of Oulu research services according to the research permit and made available inside the computing environment at data/import.
Export the Docker image to a .tar file
docker save -o visu-demo-image.tar visu-demo-image:jupyter-notebookTransfer the image (visu-demo-image.tar) to the computing environment via sftp. Also, transfer the dataset for the demo.
- Files are transferred to VISU using a secure shell file transfer protocol (SFTP).
- Create SSH-keypair
- Command line →
ssh-keygen -t ed25519→ optional file path → optional password → repeat password https://u.oulu.fi/sshkeys: login with the University of Oulu account
- Command line →
- Add the previously saved public key (
id_ed25519.pub) by copying the contents to the text field - The default folder is typically
home/.sshorC:/Users/username/.ssh - Transfer files on the command line using `sftp user@files.visu.oulu.fi
- List available environments with
lsand move to the import folder of the computing environment using cdvisu-202xxxxx/import - Transfer files to the import folder from the current local folder: `put <path/filename>
Convert the Docker image:
apptainer build visu-demo-container.sif docker-archive:visu-demo-image.tarRun the notebook:
apptainer exec \
--bind ./data:/code/data \
--env JUPYTER_RUNTIME_DIR=./tmp/jupyter-runtime \
--env JUPYTER_DATA_DIR=./tmp/jupyter-data \
visu-demo-container.sif \
jupyter lab --ip=0.0.0.0 --no-browser --notebook-dir=/codeThe
--bindflag allows access to the local data directory inside the container. A code directory could also be bind-mounted here with a,separator. The--envflags redirect Jupyter's runtime and data directories to/tmp, which is writable inside the container. Without these, Jupyter tries to write to your home directory (/users/…), which is read-only in the VISU environment. The--notebook-dirflag sets the working directory of JupyterLab to/codeinside the container.
- Docker: Press
Ctrl+Cin the terminal running JupyterLab, or rundocker stop <container_id>from another terminal (find the ID withdocker ps). If the container is started with--rm, it is removed automatically once stopped and no separate cleanup is needed. - Apptainer: Press
Ctrl+Cin the terminal running JupyterLab. Apptainer containers do not need to be removed separately.
- Port 8888 already in use: Stop the service using it, or change the port mapping, e.g.
-p 8889:8888, and openhttp://127.0.0.1:8889/...instead. - Permission errors on the bind-mounted data folder: Check that the local
datafolder exists and that your user has read/write access to it. - Apptainer build fails / runs out of space: Building the
.siffile requires temporary disk space beyond the final image size. Free up space, or setAPPTAINER_TMPDIRto a location with more room. - Jupyter tries to write to a read-only home directory: Make sure the
--envflags from Step 3 are included exactly as shown; without them Jupyter defaults to your home directory, which is read-only in VISU.
For questions regarding Sensitive data computing environment VISU and its access or research permits, contact the University of Oulu VISU support or research services.
Chicco, D., Jurman, G. Machine learning can predict survival of patients with heart failure from serum creatinine and ejection fraction alone. BMC Med Inform Decis Mak 20, 16 (2020). https://doi.org/10.1186/s12911-020-1023-5