Skip to content

Commit 6cd7808

Browse files
authored
Revise README for improved clarity and structure
Refactor README for clarity and consistency, updating sections and formatting.
1 parent f9fa280 commit 6cd7808

1 file changed

Lines changed: 82 additions & 44 deletions

File tree

README.md

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
# Fraud Detection API — FastAPI Inference Service
22

3-
This project provides a **production-style machine learning inference API**
4-
for detecting fraudulent credit card transactions.
3+
A production-style machine learning inference API for detecting fraudulent credit card transactions.
4+
The API serves a trained XGBoost fraud detection model via FastAPI, containerized with Docker and automatically deployed via a GitHub Actions CI/CD pipeline.
55

6-
The API serves a trained **XGBoost fraud detection model** via **FastAPI**,
7-
with strict input validation, feature alignment, and safe inference handling.
8-
9-
The goal of this project is to demonstrate how a trained ML model is
10-
**exposed, validated, and consumed** in a real-world system — not just trained.
6+
---
117

128
## Problem Context
139

14-
Credit card fraud detection is a **highly imbalanced classification problem**,
15-
where missing a fraudulent transaction is often more costly than flagging
16-
a legitimate one.
10+
Credit card fraud detection is a highly imbalanced classification problem, where missing a fraudulent transaction is often more costly than flagging a legitimate one.
1711

18-
In real production systems, models are rarely used directly.
19-
They must be:
12+
In real production systems, models are rarely used directly. They must be:
2013
- Validated
2114
- Properly preprocessed
2215
- Safely deployed behind an API
2316

2417
This project focuses on the **serving and inference layer** of a fraud detection system.
2518

19+
---
2620

2721
## Key Features
2822

@@ -34,47 +28,49 @@ This project focuses on the **serving and inference layer** of a fraud detection
3428
- Clear error handling with meaningful HTTP responses
3529
- Model metadata endpoint for observability
3630
- JSON-safe prediction outputs
31+
- Dockerized for consistent deployment anywhere
32+
- CI/CD pipeline via GitHub Actions → auto-builds and pushes to Docker Hub on every push
3733

34+
---
3835

3936
## Project Structure
4037

41-
```text
38+
```
4239
fraud-detection-api/
4340
├── app/
4441
│ ├── main.py # API endpoints
4542
│ ├── schemas.py # Request validation schemas
46-
│ ├── inference.py # Model inference logic
47-
│ ├── config.py # Centralized configuration
43+
│ ├── inference.py # Model inference logic
44+
│ ├── config.py # Centralized configuration
4845
│ └── __init__.py
4946
├── models/
5047
│ └── xgboost.pkl
5148
├── artifacts/
5249
│ └── standard_scaler.pkl
50+
├── .github/
51+
│ └── workflows/
52+
│ └── deploy.yml # CI/CD pipeline
53+
├── Dockerfile
5354
└── .gitignore
5455
```
5556

5657
---
5758

58-
## 📌 API Endpoints
59+
## API Endpoints
5960

60-
```markdown
61-
### Health Check :
61+
### `GET /health`
6262
Returns API health status.
6363

64-
### Model Information :
65-
Returns model metadata such as:
66-
- Model name
67-
- Version
68-
- Threshold
64+
### `GET /model-info`
65+
Returns model metadata:
66+
- Model name and version
67+
- Decision threshold
6968
- Number of features
7069

71-
### Fraud Prediction
72-
Accepts a full feature vector (Time, Amount, V1–V28) and returns
73-
a fraud probability and decision.
74-
```
75-
76-
## Example Prediction Request
70+
### `POST /predict`
71+
Accepts a full feature vector (Time, Amount, V1–V28) and returns a fraud probability and decision.
7772

73+
**Example Request:**
7874
```json
7975
{
8076
"Time": 50000,
@@ -109,30 +105,72 @@ a fraud probability and decision.
109105
"V28": -0.04
110106
}
111107
```
108+
109+
---
110+
111+
## Running with Docker
112+
113+
Pull and run directly from Docker Hub — no setup required:
114+
115+
```bash
116+
docker pull saaddot/fraud-detection-api
117+
docker run -p 8000:8000 saaddot/fraud-detection-api
118+
```
119+
120+
Then open: `http://localhost:8000/health`
121+
122+
Or build locally:
123+
```bash
124+
docker build -t fraud-detection-api .
125+
docker run -p 8000:8000 fraud-detection-api
126+
```
127+
112128
---
113129

114-
## 📌 Design Decisions
130+
## CI/CD Pipeline
131+
132+
Every push to `main` triggers a GitHub Actions workflow that:
133+
134+
1. Checks out the code on a fresh Ubuntu runner
135+
2. Logs into Docker Hub using repository secrets
136+
3. Builds the Docker image
137+
4. Pushes it to Docker Hub as `saaddot/fraud-detection-api:latest`
115138

116-
```markdown
117-
- The API expects the **same feature schema used during training**
118-
to avoid inference drift.
119-
- PCA features (V1–V28) are assumed to be computed upstream.
120-
- Only Time and Amount are scaled during inference.
121-
- Feature order is explicitly enforced before prediction.
122-
- Inference logic is separated from API routing and configuration.
123139
```
140+
Push to main
141+
142+
GitHub Actions (Ubuntu)
143+
144+
Build Docker image
145+
146+
Push to Docker Hub ← anyone can pull and run
147+
```
148+
149+
---
150+
151+
## Design Decisions
152+
153+
- The API expects the **same feature schema used during training** to avoid inference drift
154+
- PCA features (V1–V28) are assumed to be computed upstream
155+
- Only Time and Amount are scaled during inference
156+
- Feature order is explicitly enforced before prediction
157+
- Inference logic is separated from API routing and configuration
158+
159+
---
124160

125161
## Tech Stack
126162

127-
- Python
128-
- FastAPI
129-
- Pydantic
130-
- XGBoost
131-
- Scikit-learn
132-
- Pandas
163+
Python · FastAPI · Pydantic · XGBoost · Scikit-learn · Docker · GitHub Actions
164+
165+
---
166+
167+
## Related Projects
168+
169+
- [fraud-detection-ml](https://github.com/msaad-dot/fraud-detection-ml) — Model training pipeline
170+
- [drift-monitoring](https://github.com/msaad-dot/drift-monitoring) — Data drift monitoring
133171

134172
---
135173

136174
## Author
137175

138-
**Mohamed Saad**
176+
Mohamed Saad[GitHub](https://github.com/msaad-dot)

0 commit comments

Comments
 (0)