{"id":51262985,"url":"https://github.com/zouari-oss/user-risk-detection","last_synced_at":"2026-06-29T13:32:07.194Z","repository":{"id":355152212,"uuid":"1226994135","full_name":"zouari-oss/user-risk-detection","owner":"zouari-oss","description":"FastAPI-based microservice that predicts the risk level of a user session","archived":false,"fork":false,"pushed_at":"2026-05-06T21:55:11.000Z","size":7288,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-06T23:39:36.922Z","etag":null,"topics":["data-generation","data-visualization","ml","pandas","xgboost","xgboost-classifier"],"latest_commit_sha":null,"homepage":"https://user-risk-detection-api.vercel.app","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zouari-oss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-02T04:22:49.000Z","updated_at":"2026-05-06T21:55:14.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/zouari-oss/user-risk-detection","commit_stats":null,"previous_names":["zouari-oss/user-risk-detection-api","zouari-oss/user-risk-detection"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/zouari-oss/user-risk-detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouari-oss%2Fuser-risk-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouari-oss%2Fuser-risk-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouari-oss%2Fuser-risk-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouari-oss%2Fuser-risk-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zouari-oss","download_url":"https://codeload.github.com/zouari-oss/user-risk-detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zouari-oss%2Fuser-risk-detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34929698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-generation","data-visualization","ml","pandas","xgboost","xgboost-classifier"],"created_at":"2026-06-29T13:32:06.920Z","updated_at":"2026-06-29T13:32:07.184Z","avatar_url":"https://github.com/zouari-oss.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Contributors](https://img.shields.io/badge/CONTRIBUTORS-01-blue?style=plastic)](https://github.com/zouari-oss/user-risk-detection-api/graphs/contributors)\n[![Forks](https://img.shields.io/badge/FORKS-00-blue?style=plastic)](https://github.com/zouari-oss/user-risk-detection-api/network/members)\n[![Stargazers](https://img.shields.io/badge/STARS-01-blue?style=plastic)](https://github.com/zouari-oss/user-risk-detection-api/stargazers)\n[![Issues](https://img.shields.io/badge/ISSUES-00-blue?style=plastic)](https://github.com/zouari-oss/user-risk-detection-api/issues)\n[![GPL-3.0 License](https://img.shields.io/badge/LICENSE-GPL3.0-blue?style=plastic)](https://raw.githubusercontent.com/zouari-oss/user-risk-detection-api/refs/heads/main/LICENSE)\n[![Linkedin](https://img.shields.io/badge/Linkedin-7k-blue?style=plastic)](https://www.linkedin.com/in/zouari-omar)\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/zouari-oss/user-risk-detection-api\"\u003e\n    \u003cimg src=\"https://github.com/zouari-oss/user-risk-detection-api/raw/main/res/img/logo.png\" alt=\"user-risk-detection-api.png\" width=\"300\"\u003e\n  \u003c/a\u003e\n  \u003ch1\u003euser-risk-detection-api\u003c/h1\u003e\n  \u003ch6\u003eFastAPI-based microservice that predicts the risk level of a user session\u003c/h6\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#overview\"\u003eOverview\u003c/a\u003e •\n  \u003ca href=\"#key-features\"\u003eKey Features\u003c/a\u003e •\n  \u003ca href=\"#risk-classes\"\u003eRisk Classes\u003c/a\u003e •\n  \u003ca href=\"#model-performance\"\u003eModel Performance\u003c/a\u003e •\n  \u003ca href=\"#dataset-generation\"\u003eDataset Generation\u003c/a\u003e •\n  \u003ca href=\"#api-example\"\u003eAPI Example\u003c/a\u003e •\n  \u003ca href=\"#usage\"\u003eUsage\u003c/a\u003e •\n  \u003ca href=\"#download\"\u003eDownload\u003c/a\u003e •\n  \u003ca href=\"#emailware\"\u003eEmailware\u003c/a\u003e •\n  \u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e •\n  \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e •\n  \u003ca href=\"#contact\"\u003eContact\u003c/a\u003e •\n  \u003ca href=\"#acknowledgments\"\u003eAcknowledgments\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/FastAPI-Web%20Framework-009688?style=for-the-badge\u0026logo=fastapi\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge\u0026logo=python\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/XGBoost-Gradient%20Boosting-AA4A44?style=for-the-badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Pandas-Data%20Analysis-150458?style=for-the-badge\u0026logo=pandas\u0026logoColor=white\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Matplotlib-Visualization-11557C?style=for-the-badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Machine%20Learning-Modeling-success?style=for-the-badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/API-RESTful-informational?style=for-the-badge\"/\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Open%20Source-Yes-3DA639?style=for-the-badge\u0026logo=opensourceinitiative\u0026logoColor=white\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"res/img/benchmark.png\"/\u003e\n\u003c/p\u003e\n\n## Overview\n\n**user-risk-detection-api** is a FastAPI-based microservice that predicts the risk level of a user session using behavioral signals such as:\n\n- IP changes\n- device switching\n- location anomalies\n- login time patterns\n- session duration\n\nThe model outputs a **risk classification (0 / 1 / 2)** along with probabilities.\n\n## Key Features\n\n- FastAPI REST API with `/docs` (Swagger UI)\n- ML model powered by **XGBoost**\n- Multiclass classification (safe / medium / risky)\n- Probability output for each class\n- Trained on large synthetic dataset (500k+ rows)\n- Deterministic + noise-injected data generation\n- Fraud-oriented feature engineering\n- CORS enabled (frontend ready)\n\n## Risk Classes\n\n| Label | Meaning     |\n| ----- | ----------- |\n| 0     | Safe        |\n| 1     | Medium Risk |\n| 2     | High Risk   |\n\n![class_distribution](res/img/dataset/class_distribution.png)\n![feature_distributions](res/img/dataset/feature_distributions.png)\n\n## Model Performance\n\n- Accuracy: ~94–96%\n- Balanced multiclass performance\n- Robust against noisy inputs\n- Tuned fraud detection threshold\n\n![plot_feature_importance](res/img/model/plot_feature_importance.png)\n![plot_decision_tree](res/img/model/plot_decision_tree.png)\n\n## Dataset Generation\n\nSynthetic dataset includes:\n\n- 500,000+ unique rows\n- Zero duplicates\n- Controlled class balance\n- Realistic noise injection\n\n## API Example\n\n### Endpoint\n\n```http\nPOST /api/v1/predict\nContent-Type: application/json\n```\n\n### Request\n\n```json\n{\n  \"session_duration\": 180,\n  \"is_revoked\": 0,\n  \"ip_change_count\": 2,\n  \"device_change_count\": 1,\n  \"location_change\": 0,\n  \"login_hour\": 10,\n  \"is_night_login\": 0,\n  \"os_variation\": 2\n}\n```\n\n### Response\n\n```json\n{\n  \"prediction\": 1,\n  \"confidence\": 0.87,\n  \"probabilities\": [0.1, 0.87, 0.03]\n}\n```\n\n## Usage\n\n```bash\ngit clone https://github.com/zouari-oss/user-risk-detection-api\ncd user-risk-detection-api/project\n\nchmod +x setup \u0026\u0026 ./setup\nfastapi run\n```\n\n\u003e [!NOTE]\n\u003e API available at: \u003chttp://localhost:8000/docs\u003e\n\n## Download\n\nYou 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.\n\n## Emailware\n\nuser-risk-detection-api is an emailware. Meaning, if you liked using this app or it has helped you in any way,\nwould like you send as an email at \u003czouariomar20@gmail.com\u003e about anything you'd want to say about\nthis software. I'd really appreciate it!\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis 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.\n\n## Contact\n\nFor questions or suggestions, feel free to reach out:\n\n- **GitHub**: [zouari-oss](https://github.com/zouari-oss)\n- **Email**: \u003czouariomar20@gmail.com\u003e\n- **LinkedIn**: [zouari-omar](https://www.linkedin.com/in/zouari-omar)\n\n## Acknowledgments\n\nBuilt with ❤️ for the open-source community.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzouari-oss%2Fuser-risk-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzouari-oss%2Fuser-risk-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzouari-oss%2Fuser-risk-detection/lists"}