Skip to content

zouari-oss/user-risk-detection-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Contributors Forks Stargazers Issues GPL-3.0 License Linkedin

user-risk-detection-api.png

user-risk-detection-api

FastAPI-based microservice that predicts the risk level of a user session

OverviewKey FeaturesRisk ClassesModel PerformanceDataset GenerationAPI ExampleUsageDownloadEmailwareContributingLicenseContactAcknowledgments

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

class_distribution feature_distributions

Model Performance

  • Accuracy: ~94–96%
  • Balanced multiclass performance
  • Robust against noisy inputs
  • Tuned fraud detection threshold

plot_feature_importance plot_decision_tree

Dataset Generation

Synthetic dataset includes:

  • 500,000+ unique rows
  • Zero duplicates
  • Controlled class balance
  • Realistic noise injection

API Example

Endpoint

POST /api/v1/predict
Content-Type: application/json

Request

{
  "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

{
  "prediction": 1,
  "confidence": 0.87,
  "probabilities": [0.1, 0.87, 0.03]
}

Usage

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: http://localhost:8000/docs

Download

You can download 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 zouariomar20@gmail.com 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 file for details.

Contact

For questions or suggestions, feel free to reach out:

Acknowledgments

Built with ❤️ for the open-source community.

About

FastAPI-based microservice that predicts the risk level of a user session

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Contributors