File size: 3,226 Bytes
dbd8767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
license: mit
library_name: sklearn
pipeline_tag: tabular-classification
tags:
- fraud-detection
- logistic-regression
- baseline
- tabular-classification
datasets:
- Marvinds/synthetic-bank-transactions
metrics:
- roc_auc
- average_precision
model-index:
- name: fraud-baseline-logreg
  results:
  - task:
      type: tabular-classification
    dataset:
      name: Synthetic Bank Transactions
      type: Marvinds/synthetic-bank-transactions
    metrics:
    - type: average_precision
      value: 0.7203
      name: PR-AUC (time-based test split)
    - type: roc_auc
      value: 0.9849
      name: ROC-AUC (time-based test split)
---

# fraud-baseline-logreg

A deliberately simple **logistic-regression baseline** for fraud detection, trained on
[Marvinds/synthetic-bank-transactions](https://huggingface.co/datasets/Marvinds/synthetic-bank-transactions).

## Why this project

Every later experiment I run (gradient boosting, sequence models, graph features) needs a number
to beat. A baseline that's transparent, quick to retrain and honestly evaluated is that number.
Logistic regression fits the job: its coefficients show what the model learned, and that can
be checked against the known fraud mechanism of the synthetic dataset.

It also practises two habits from production fraud systems:
- **time-based evaluation** (train on the past, test on the future), never a random split;
- **PR-AUC and recall at a fixed precision** instead of accuracy, because accuracy is meaningless
  at a 0.6% fraud rate (predicting "never fraud" scores 99.4%).

## Results

Time-based split: first 80% of transactions for training, last 20% (20,000 rows, 0.6% fraud) for testing.

| Metric | Value |
|---|---|
| ROC-AUC | 0.9849 |
| **PR-AUC** | **0.7203** |
| Recall @ precision ≥ 0.5 | 0.7355 |
| Recall @ precision ≥ 0.8 | 0.6281 |

Strongest coefficients: `txn_count_24h` (+1.66) and `amount_vs_avg` (+1.61), which match the
velocity and amount-spike pattern injected by the generator. Full list is in `metrics.json`.

> These numbers come from synthetic data with a known generator. They show the pipeline works.
> They are **not** a claim about real-world fraud performance.

## Features

`log(amount)`, `amount_vs_avg`, `txn_count_24h`, `is_foreign`, `is_new_device`, `is_night` (00–04),
plus one-hot `merchant_category` and `channel`. Standard-scaled, `class_weight="balanced"`.

## Usage

```python
import hashlib, joblib, pandas as pd
from huggingface_hub import hf_hub_download

path = hf_hub_download("Marvinds/fraud-baseline-logreg", "model.joblib")
expected = open(hf_hub_download("Marvinds/fraud-baseline-logreg", "model.joblib.sha256")).read().strip()
assert hashlib.sha256(open(path, "rb").read()).hexdigest() == expected
model = joblib.load(path)  # pickle: only load files you trust
```

Input must have the feature columns listed above (see `features()` in `train.py`).
Trained with scikit-learn 1.9.1.

## Reproduce

```bash
uv run train.py --data path/to/transactions.csv --out model
```

## Next experiments

- [ ] HistGradientBoosting vs this baseline, same split
- [ ] Probability calibration and threshold selection based on review-queue capacity
- [ ] Performance under concept drift (dataset v2)