https://github.com/zouari-oss/user-risk-detection
FastAPI-based microservice that predicts the risk level of a user session
https://github.com/zouari-oss/user-risk-detection
data-generation data-visualization ml pandas xgboost xgboost-classifier
Last synced: about 1 hour ago
JSON representation
FastAPI-based microservice that predicts the risk level of a user session
- Host: GitHub
- URL: https://github.com/zouari-oss/user-risk-detection
- Owner: zouari-oss
- License: gpl-3.0
- Created: 2026-05-02T04:22:49.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-06T21:55:11.000Z (about 2 months ago)
- Last Synced: 2026-05-06T23:39:36.922Z (about 2 months ago)
- Topics: data-generation, data-visualization, ml, pandas, xgboost, xgboost-classifier
- Language: Python
- Homepage: https://user-risk-detection-api.vercel.app
- Size: 6.95 MB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Authors: AUTHORS
Awesome Lists containing this project
README
[](https://github.com/zouari-oss/user-risk-detection-api/graphs/contributors)
[](https://github.com/zouari-oss/user-risk-detection-api/network/members)
[](https://github.com/zouari-oss/user-risk-detection-api/stargazers)
[](https://github.com/zouari-oss/user-risk-detection-api/issues)
[](https://raw.githubusercontent.com/zouari-oss/user-risk-detection-api/refs/heads/main/LICENSE)
[](https://www.linkedin.com/in/zouari-omar)
Overview •
Key Features •
Risk Classes •
Model Performance •
Dataset Generation •
API Example •
Usage •
Download •
Emailware •
Contributing •
License •
Contact •
Acknowledgments
## Overview
**user-risk-detection-api** is a FastAPI-based microservice that predicts the risk level of a user session using behavioral signals such as:
- IP changes
- device switching
- location anomalies
- login time patterns
- session duration
The model outputs a **risk classification (0 / 1 / 2)** along with probabilities.
## Key Features
- FastAPI REST API with `/docs` (Swagger UI)
- ML model powered by **XGBoost**
- Multiclass classification (safe / medium / risky)
- Probability output for each class
- Trained on large synthetic dataset (500k+ rows)
- Deterministic + noise-injected data generation
- Fraud-oriented feature engineering
- CORS enabled (frontend ready)
## Risk Classes
| Label | Meaning |
| ----- | ----------- |
| 0 | Safe |
| 1 | Medium Risk |
| 2 | High Risk |


## Model Performance
- Accuracy: ~94–96%
- Balanced multiclass performance
- Robust against noisy inputs
- Tuned fraud detection threshold


## Dataset Generation
Synthetic dataset includes:
- 500,000+ unique rows
- Zero duplicates
- Controlled class balance
- Realistic noise injection
## API Example
### Endpoint
```http
POST /api/v1/predict
Content-Type: application/json
```
### Request
```json
{
"session_duration": 180,
"is_revoked": 0,
"ip_change_count": 2,
"device_change_count": 1,
"location_change": 0,
"login_hour": 10,
"is_night_login": 0,
"os_variation": 2
}
```
### Response
```json
{
"prediction": 1,
"confidence": 0.87,
"probabilities": [0.1, 0.87, 0.03]
}
```
## Usage
```bash
git clone https://github.com/zouari-oss/user-risk-detection-api
cd user-risk-detection-api/project
chmod +x setup && ./setup
fastapi run
```
> [!NOTE]
> API available at:
## Download
You can [download](https://github.com/zouari-oss/user-risk-detection-api/releases) the latest installable version of user-risk-detection-api for Windows, macOS and Linux.
## Emailware
user-risk-detection-api is an emailware. Meaning, if you liked using this app or it has helped you in any way,
would like you send as an email at about anything you'd want to say about
this software. I'd really appreciate it!
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This repository is licensed under the **GPL-3.0 License**. You are free to use, modify, and distribute the content. See the [LICENSE](LICENSE) file for details.
## Contact
For questions or suggestions, feel free to reach out:
- **GitHub**: [zouari-oss](https://github.com/zouari-oss)
- **Email**:
- **LinkedIn**: [zouari-omar](https://www.linkedin.com/in/zouari-omar)
## Acknowledgments
Built with ❤️ for the open-source community.