> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mathfi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Healthcare outcome prediction

> Healthcare prediction use case: classify patient outcomes using MathFi.ai balanced-class learning on tabular clinical data.

### The problem: health anomaly detection in ECG signals

Detecting anomalies within human heart ECG signals can help health practitioners identify and diagnose potentially fatal heart conditions to prevent heart attacks or cure heart diseases saving patients' lives.

### The data

In this use case, we will use a labelled ECG training data to use MathFi.ai platform to detect the ECG anomaly patterns. The data includes samples of ECG time series taken from multiple ECG sensors on human body:

* Each training sample is a sampled ECG signal as a time series
* The last column is the target of the ECG anomaly detection. Label `1` indicates the presence of an anomaly and label `0` means that there is no anomaly
* The dataset used is the altered version of the dataset in [http://www.timeseriesclassification.com/description.php?Dataset=ECG5000](http://www.timeseriesclassification.com/description.php?Dataset=ECG5000)

The base dataset used is (<a href="/files/healthcare/ecg-anomaly-labelled-dataset.csv" target="_blank">ECGAnomaly.csv</a>).

<br />

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/healthcare/ecg-anomaly-labelled-dataset-csv.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=4de987b59c953272ba997206fb7aac4e" alt="ECG CSV" width="1863" height="729" data-path="images/usecases/healthcare/ecg-anomaly-labelled-dataset-csv.png" />

<br />

### Dataset creation

Use the following parameters for dataset creation:

* **number of buckets**: `20`

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/healthcare/ecg-anomaly-dataset-creation.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=5293448e4d898f3a59a1fb2fe301925a" alt="Dataset creation" width="1375" height="631" data-path="images/usecases/healthcare/ecg-anomaly-dataset-creation.png" />

<br />

### Training

This is the best training attempt:

* **scaling factor**: `19`
* **performance threshold**: `0.99`

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/healthcare/ecg-anomaly-best-training.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=9ccc18c71a8c1cf5e8285d23f9553828" alt="Training params" width="1375" height="636" data-path="images/usecases/healthcare/ecg-anomaly-best-training.png" />

And the created *champion model*:

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/healthcare/ecg-anomaly-training-result.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=a1dda962e2d1b1b4ead278d9217f940f" alt="Training best" width="1379" height="644" data-path="images/usecases/healthcare/ecg-anomaly-training-result.png" />

<br />

The final performance of `0.99` was achieved after few iterations of [hyperparameter tuning](/guides/hyperparameter-tuning):

| Number of Buckets | Scaling Factor | Performance Threshold |
| ----------------: | -------------: | --------------------: |
|                20 |             19 |                  0.80 |
|                20 |             19 |                  0.98 |
|                20 |             19 |                  0.99 |

<br />

### Final result

When performing binary classifications or predictions, MathFi.ai platform's underlying proprietary algorithms calculate the probability of certainty for a prediction outcome.

* One label (e.g.`1`) will be selected when the probability is equal or above `0.5`
* and the other one (e.g. `0`) will be selected when the probability is below `0.5`

The closer the value is to `0` or `1`, the more certain is the prediction. The probability is presented in a dedicated column in the prediction result file.

Using <a href="/files/healthcare/ecg-anomaly-unseen-nolabels.csv" target="_blank">this unseen unlabelled data</a>, the <a href="/files/healthcare/ecg-anomaly-prediction-result.csv" target="_blank">resulting CSV</a> looks like this:

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/healthcare/ecg-anomaly-prediction-result.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=c058af089ed1cef0ccba44433dcf15ef" alt="Prediction 2" width="324" height="717" data-path="images/usecases/healthcare/ecg-anomaly-prediction-result.png" />

***

**Build this yourself** — Follow the [Quickstart](/quickstart) to run your first prediction, or go straight to [API Recipes](/developers/api-recipes) to integrate programmatically.
