> ## 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.

# Self-checkout fraud detection

> Self-checkout fraud detection to identify fraudulent retail transactions with balanced-class ML on tabular data.

### The problem: self-checkout fraudulent activity detection

The number of self-checkout stations is on the rise, helping avoid long lines while speeding up the paying process for individual customers. But retailers should be able to decide which purchases to check to prevent revenue loss and expose fraudsters without annoying innocent customers.

MathFi.ai platform can help retailers detect the suspicious self-checkout activities seamlessly. We use a labelled training data based on anonymous real-life customer self-checkout data to train the models.

### The data

In this case, we're going to develop a **binary classification model** to detect which self-checkouts to check.

The base dataset (<a href="/files/self-checkout-fraud/self-checkout-fraud-labelled.csv" target="_blank">SelfCheckoutFraud.csv</a>) includes the following features:

| Parameter | Units / Type          | Description                                                                      |
| --------- | --------------------- | -------------------------------------------------------------------------------- |
| `ID`      | identifier            | ID of the self-checkout purchase session.                                        |
| `P1`      | numeric (score)       | Trust level in the customer based on past purchase history, credit history, etc. |
| `P2`      | seconds               | Total scan time in seconds.                                                      |
| `P3`      | seconds               | Total shopping time.                                                             |
| `P4`      | count                 | Number of voids of line items.                                                   |
| `P5`      | count                 | Number of scans without registration.                                            |
| `P6`      | count                 | Number of quantity modifications.                                                |
| `P7`      | rate (items/sec)      | Number of scanned line items per second.                                         |
| `P8`      | rate (value/sec)      | Purchase value per second.                                                       |
| `P9`      | rate (voids/position) | Number of line item voids per position.                                          |
| `Fraud`   | categorical (0/1)     | Target variable — `0` if normal, `1` if fraudulent.                              |

<br />

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/self-checkout-fraud/self-checkout-fraud-labelled-csv.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=c3c20708446d3a5b0d20b64d34d7d183" alt="Self Checkout CSV" width="754" height="689" data-path="images/usecases/self-checkout-fraud/self-checkout-fraud-labelled-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/self-checkout-fraud/self-checkout-fraud-dataset-creation.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=eccf7efcef8d4dd8eaab636aa31610fc" alt="Dataset creation" width="1376" height="591" data-path="images/usecases/self-checkout-fraud/self-checkout-fraud-dataset-creation.png" />

<br />

### Training

This is the best training attempt:

* **scaling factor**: `200`
* **performance threshold**: `0.97`

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/self-checkout-fraud/self-checkout-fraud-best-training.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=0a0ee84021db7e707ed311f9e3433bf1" alt="Training params" width="1375" height="606" data-path="images/usecases/self-checkout-fraud/self-checkout-fraud-best-training.png" />

And the created *champion model*:

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/self-checkout-fraud/self-checkout-fraud-training-result.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=ad798d0a866da87f634b8f104a5bbf67" alt="Training best" width="1377" height="641" data-path="images/usecases/self-checkout-fraud/self-checkout-fraud-training-result.png" />

<br />

The final performance of `0.97` 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.90 |
|                20 |             19 |                  0.95 |
|                20 |             80 |                  0.97 |
|                20 |            200 |                  0.97 |

<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/self-checkout-fraud/self-checkout-unseen.csv" target="_blank">this unseen unlabelled data</a>, the <a href="/files/self-checkout-fraud/self-checkout-fraud-prediction-result.csv" target="_blank">resulting labelled CSV</a> looks like this:

* With **88%** Accuracy: `27` out of `31` fraud cases were detected successfully.

<img src="https://mintcdn.com/mathficast/XHYtrrIKg310YHlO/images/usecases/self-checkout-fraud/self-checkout-fraud-prediction-result.png?fit=max&auto=format&n=XHYtrrIKg310YHlO&q=85&s=822672c0c2641c10bfa2f08b5eac0771" alt="Prediction 2" width="1915" height="905" data-path="images/usecases/self-checkout-fraud/self-checkout-fraud-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.
