Code Monkey home page Code Monkey logo

uci-heart-failure's Introduction

UCI-Heart-Failure

Setup:

Clone the repository:

git clone [email protected]:Allaway11/uci-heart-failure.git

create a virtual environment and install packages in requirements.txt

python3 -m venv venv && source venv/bin/activate

and then,

pip install -r requirements.txt

The dataset being used is: https://archive.ics.uci.edu/ml/datasets/Heart+failure+clinical+records

and can be downloaded to the data directory using the following command executed in the terminal:

wget https://archive.ics.uci.edu/ml/machine-learning-databases/00519/heart_failure_clinical_records_dataset.csv -P data/

To train the ML models we next need to create a training dataset and a holdout test dataset. To achieve this we can use the create_test_dataset.py script to split the original dataset into a training dataset (data/train.json) with 80% of the data and a holdout test set with 20% of the data (data/test.json). An example json file to be used as part of the curl request to the model server api is also generated - this contains the first example in the test dataset (data/test_post_request.json).

python -m create_test_dataset

Model Serving

As this dataset is small (299 examples in total) only simple ML models have been chosen (Random Forests, SVM, MLPs) in the ensemble to avoid overfitting. Due to the lightweight resource requirements of the models, training of the model occurs on server start up.

The models can be trained and benchmarked by running the following command from the repo root:

python -m train

This should result in the following output:

              precision    recall  f1-score   support

           0       0.84      0.88      0.86        41
           1       0.71      0.63      0.67        19

    accuracy                           0.80        60
   macro avg       0.77      0.75      0.76        60
weighted avg       0.80      0.80      0.80        60

To start up the server and train the model we can run the following command from the root of the repo in the terminal:

uvicorn api:app

We can then test out a post request on the "/predict" endpoint using the browser at http://localhost:8000/docs and use a request body such as

{
  "features":{
    "age":94.0,
    "anaemia":0.0,
    "creatinine_phosphokinase":582.0,
    "diabetes":1.0,
    "ejection_fraction":38.0,
    "high_blood_pressure":1.0,
    "platelets":263358.03,
    "serum_creatinine":1.83,
    "serum_sodium":134.0,
    "sex":1.0,
    "smoking":0.0,
    "time":27.0
  }
}

or send a curl request from the root of the repo e.g.:

curl -X POST --header "Content-Type: application/json" -d @data/test_post_request.json http://localhost:8000/predict   

Tests

To run the unit tests associated with the api run the following command in the terminal from the root of the repo:

python -m pytest test_api.py --cov=api --cov-report=term

uci-heart-failure's People

Contributors

allaway11 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.