Overview • Key Features • Risk Classes • Model Performance • Dataset Generation • API Example • Usage • Download • Emailware • Contributing • License • Contact • Acknowledgments
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.
- 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)
| Label | Meaning |
|---|---|
| 0 | Safe |
| 1 | Medium Risk |
| 2 | High Risk |
- Accuracy: ~94–96%
- Balanced multiclass performance
- Robust against noisy inputs
- Tuned fraud detection threshold
Synthetic dataset includes:
- 500,000+ unique rows
- Zero duplicates
- Controlled class balance
- Realistic noise injection
POST /api/v1/predict
Content-Type: application/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
}{
"prediction": 1,
"confidence": 0.87,
"probabilities": [0.1, 0.87, 0.03]
}git clone https://github.com/zouari-oss/user-risk-detection-api
cd user-risk-detection-api/project
chmod +x setup && ./setup
fastapi runNote
API available at: http://localhost:8000/docs
You can download the latest installable version of user-risk-detection-api for Windows, macOS and Linux.
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 zouariomar20@gmail.com about anything you'd want to say about this software. I'd really appreciate it!
Contributions are welcome! Please feel free to submit a Pull Request.
This repository is licensed under the GPL-3.0 License. You are free to use, modify, and distribute the content. See the LICENSE file for details.
For questions or suggestions, feel free to reach out:
- GitHub: zouari-oss
- Email: zouariomar20@gmail.com
- LinkedIn: zouari-omar
Built with ❤️ for the open-source community.




