Skip to content

davifmdhack/adeno_predict

Repository files navigation

Adeno Predict

UNICAMP logo

GitHub Page Authors

Davi Ferreira MD., MSc.

Send e-mail to Davi Ferreira

Fernanda Veloso MD., PhD. candidate

Send e-mail to Fernanda

Introduction

This repository (Adeno Predict) serves the purpose of applying machine learning algorithms to predict the consistency of pituitary macroadenomas from demographic data and brain MRI parameters. The objective of this application is to optimize the ability to predict non-soft consistency and consequently improve surgical planning and ultimately reduce post-surgical complications.

Using a database of 70 patients from Hospital de Clínicas of the State University of Campinas (HC-UNICAMP). Our group evaluated the following classification algorithms: Decision Tree (DT), K-Nearest Neighbors (KNN), Support Vector Machine (SVM), and an ensemble of the two best models (DT and SVM).

In this repository, we organized the code according to the following steps: example dataset in the dataset folder (dataset_example.csv), imputation of missing values (imputation), parameter tuning flow using a Leave-One-Out cross-validation (LOOCV) strategy (workflow_algorithms), and metrics and bootstrap analysis (metrics).

Dataset format

Because data collection was carried out in a single research center, it was not necessary to build a server, implement a cluster, or distributed processing. The dataset structure is similar to the provided dataset_example.csv in the dataset folder. The features used are described in features_detail.md.

Imputation missing values

The imputation process was used according to Van Buuren criteria, six values for ADC and eleven for consistency. KNN was used for deterministic process and multiple imputation by chained equations (MICE) with linear regression for stochastic methods. More information in imputation folder.

Workflow algorithms

We applied a scikit-learn pipeline to the pre-processed dataset for each algorithm, considering specifics such as standardization of numerical variables. A Leave-One-Out cross-validation (LOOCV) procedure (leave_one_out.md) was used to find the best_model for each algorithm considering the parameters (algorithms_parameters.md).

Metrics and bootstrap implementation

We used the following metrics considering the nature of the problem and its class imbalance: (1) ROC Area Under the Curve (AUC), (2) Average Precision (PR AUC), (3) Sensitivity (Recall), (4) Specificity, (5) F1 score, and (6) Matthews Correlation Coefficient (MCC). The formulas and bootstrap techniques are described in the metrics folder. Bootstrap was used to compute 95% confidence intervals (n = 1000) after finding the best threshold (bootstrap_code.md).

Clone repository and application for domestic dataset

We have developed a step-by-step guide, available in clone_repository > repository_clone.md, so that researchers can apply our trained model if they have the necessary information.

At the moment, this application is limited to databases that have all the required values. In the future, we will implement a method for imputing missing data.

How to run local predictions

  1. Install dependencies (preferably with uv or pip):

    uv sync
    # or
    pip install -e .
  2. Use the Python API to predict consistency from a DataFrame:

    import pandas as pd
    from adenopredict.inference import load_model, predict_dataframe
    
    df = pd.read_csv("dataset/dataset_example.csv")
    model = load_model("examples/best_model_svm.pkl")
    preds = predict_dataframe(model, df)
    print(preds.head())
  3. Run the Streamlit app (localhost):

    streamlit run streamlit_app.py

    Upload a .csv with columns: age, sex, diameter, adc (optional consistency). The app returns per-row probabilities and the predicted class.

Windows Quickstart (Streamlit App)

Follow these steps on Windows 10/11:

  1. Install Python 3.11 (from the Microsoft Store or python.org). During setup, check "Add Python to PATH".

  2. Open PowerShell and clone the repository:

git clone https://github.com/davifmdhack/AdenoPredict.git
cd AdenoPredict
  1. Create and activate a virtual environment:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
  1. Install dependencies:
pip install -e .
  1. Run the app:
streamlit run streamlit_app.py
  1. Upload your CSV with columns age, sex, diameter, adc (optional consistency). The app will generate probabilities and predictions. Results are saved to results/df_prediction-results.csv.

One-click (Windows)

If you prefer, you can use the provided launcher to install and run everything automatically:

  1. Double-click run_windows.bat

  2. The script will:

    • Create a virtual environment .venv

    • Install project dependencies with pip install -e .

    • Start the app via Streamlit

  3. After installation, subsequent runs will be faster. You can always launch via the same run_windows.bat.

Troubleshooting on Windows

  • If PowerShell blocks scripts, run: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned and re-activate the venv.

  • If Streamlit fails to open a browser, copy the printed local URL and paste it in your browser.

  • If you use WSL, run the same commands in your Linux shell. Ensure images are accessible via relative paths.


Article

Springer DOI


References

  1. van Buuren S. Flexible Imputation of Missing Data, Second Edition. Second edition. | Boca Raton, Florida : CRC Press, [2019] |: Chapman and Hall/CRC; 2018. doi: 10.1201/9780429492259.

  2. Mas̕s, S. (2021). Interpretable Machine Learning with Python : Learn to Build Interpretable High-performance Models with Hands-on Real-world Examples. 1st Edition, Packt Publishing, Birmingham.

  3. Garbin, C., & Marques, O. (2022). Assessing Methods and Tools to Improve Reporting, Increase Transparency, and Reduce Failures in Machine Learning Applications in Health Care. Radiology: Artificial Intelligence, 4(2). https://doi.org/10.1148/ryai.210127.

  4. Rouzrokh, P., Khosravi, B., Faghani, S., Moassefi, M., Garcia, D. V. V., Singh, Y., Zhang, K., Conte, G. M., & Erickson, B. J. (2022). Mitigating Bias in Radiology Machine Learning: 1. Data Handling. Radiology: Artificial Intelligence, 4(5). https://doi.org/10.1148/ryai.210290.

  5. Faghani, S., Khosravi, B., Zhang, K., Moassefi, M., Jagtap, J. M., Nugen, F., Vahdati, S., Kuanar, S. P., Rassoulinejad-Mousavi, S. M., Singh, Y., Vera Garcia, D. v., Rouzrokh, P., & Erickson, B. J. (2022). Mitigating Bias in Radiology Machine Learning: 3. Performance Metrics. Radiology: Artificial Intelligence, 4(5). https://doi.org/10.1148/ryai.220061.

  6. Murphy KP. Probabilistic machine learning : advanced topics. Cambridge, Massachusetts: The MIT Press; 2023.


Institutional


FCM/UNICAMP logo

School of Medical Sciences State University of Campinas - FCM/UNICAMP


Institutional Partnership


ITA logo

Aeronautics Institute of Technology - ITA


Custom License
Copyright (c) 2024 Davi Ferreira