Skip to content

Commit cf8c020

Browse files
committed
2 parents 79ad101 + 0b6beb8 commit cf8c020

1 file changed

Lines changed: 25 additions & 253 deletions

File tree

README.md

Lines changed: 25 additions & 253 deletions
Original file line numberDiff line numberDiff line change
@@ -1,221 +1,11 @@
1-
<<<<<<< HEAD
2-
**🏴‍☠️ Oasis Security – Crime Predictor
3-
4-
Modèle de prédiction de la délinquance en France (taux pour 100 000 habitants) intégré dans l’écosystème Oasis Security.
5-
L’objectif est de fournir un pipeline complet et industrialisable : de l’exploration à la mise en production (modèle sérialisé, API, CI/CD, MLflow).
6-
1. Objectifs du projet
7-
8-
Construire un modèle de prévision des taux de délinquance (par indicateur) à partir des données publiques de la police et de la gendarmerie (data.gouv.fr).
9-
10-
Fournir une implémentation production-ready :
11-
12-
Structure de projet claire (src/, models/, mlruns/, tests/).
13-
14-
Modèle sérialisé (crime_predictor.pkl) et facilement re-chargeable.
15-
16-
Scripts d’entraînement, d’inférence et de génération de rapports.
17-
18-
S’intégrer proprement dans un dépôt Oasis Security (vision sécurité & monitoring), avec une base solide pour un déploiement via Docker / GitHub Actions / MLflow.
19-
20-
2. Structure du dépôt
21-
22-
Structure simplifiée pour la partie modèle :
23-
24-
bash
25-
oasis-security-complete/
26-
├── models/
27-
│ └── crime_predictor/
28-
│ ├── src/
29-
│ │ ├── model.py # Classe CrimeRatePredictor (LinearRegression picklable)
30-
│ │ ├── generate_model.py # Script de génération du premier modèle .pkl
31-
│ │ ├── train.py # (prévu) pipeline d'entraînement complet + MLflow
32-
│ │ ├── predict.py # (prévu) API FastAPI pour l’inférence
33-
│ │ └── config.yaml # (prévu) hyperparamètres & config data
34-
│ ├── models/
35-
│ │ └── crime_predictor.pkl # Modèle sérialisé (R² ~ 0.80 sur données simulées)
36-
│ ├── mlruns/ # Répertoire MLflow (tracking local)
37-
│ ├── tests/ # Tests unitaires (à compléter)
38-
│ └── requirements.txt # Dépendances Python pour ce module
39-
├── docs/
40-
│ └── crime_predictor/ # (prévu) dashboard / documentation front
41-
└── .github/
42-
└── workflows/ # (prévu) CI/CD pour tests + build modèle/API
43-
44-
3. Données & Modélisation
45-
3.1 Source de données
46-
47-
Données issues de data.gouv.fr : base statistique de la délinquance enregistrée par la police et la gendarmerie (niveau régional / communal, par indicateur, par année).
48-
49-
Exemples de variables disponibles :
50-
51-
annee, Code_region, indicateur, nombre, insee_pop, …
52-
53-
Calcul du taux pour 100 000 habitants = nombre/insee_pop∗100000nombre/insee_pop∗100000.
54-
55-
Remarque : pour la première version de crime_predictor.pkl, un jeu de données simulé est utilisé pour garantir un modèle picklable et stable (LinearRegression), en attendant le branchement final sur la vraie source data.gouv.
56-
57-
3.2 Modèle actuel
58-
59-
Dans models/crime_predictor/src/model.py :
60-
61-
Classe centrale : CrimeRatePredictor
62-
63-
Modèle : LinearRegression (scikit-learn) pour garantir :
64-
65-
sérialisation simple via joblib,
66-
67-
robustesse sur différentes versions de Python,
68-
69-
compatibilité avec une future montée en complexité (XGBoost/LightGBM, Prophet, etc.).
70-
71-
Fonctionnalités clés :
72-
73-
train(data_url: str) -> dict
74-
Entraîne le modèle sur des features simulées (actuellement) et renvoie des métriques (R²).
75-
76-
save(path: str)
77-
Sérialise le modèle + méta-données (noms de variables, flag is_trained) dans un .pkl.
78-
79-
Ce design te permet ensuite de remplacer très facilement le bloc de génération de données par un vrai pipeline EDA + feature engineering basé sur ton notebook d’analyses.
80-
4. Installation & utilisation
81-
4.1 Prérequis
82-
83-
Python 3.13 (ou 3.11+) dans un environnement virtuel (.venv).
84-
85-
pip à jour.
86-
87-
4.2 Installation des dépendances
88-
89-
Depuis la racine du projet oasis-security-complete :
90-
91-
bash
92-
cd models/crime_predictor
93-
pip install -r requirements.txt
94-
95-
Le fichier requirements.txt contient notamment :
96-
97-
pandas
98-
99-
numpy
100-
101-
scikit-learn
102-
103-
joblib
104-
105-
(et, pour les futures étapes) fastapi, uvicorn, mlflow, pyyaml, etc.
106-
107-
4.3 Générer (ou régénérer) le modèle
108-
109-
Depuis models/crime_predictor/src :
110-
111-
bash
112-
cd models/crime_predictor/src
113-
python generate_model.py
114-
115-
Ce script :
116-
117-
instancie CrimeRatePredictor,
118-
119-
entraîne un modèle LinearRegression sur des données simulées,
120-
121-
sérialise le modèle dans :
122-
123-
bash
124-
models/crime_predictor/models/crime_predictor.pkl
125-
126-
4.4 Charger le modèle dans un autre script
127-
128-
Exemple minimal :
129-
130-
python
131-
from pathlib import Path
132-
import joblib
133-
import numpy as np
134-
135-
# Charger le modèle
136-
model_path = Path(__file__).resolve().parents[1] / "models" / "crime_predictor.pkl"
137-
data = joblib.load(model_path)
138-
139-
regressor = data["model"]
140-
feature_names = data["features"]
141-
142-
# Exemple de prédiction
143-
X_sample = np.random.randn(1, len(feature_names))
144-
y_pred = regressor.predict(X_sample)
145-
146-
print("Features:", feature_names)
147-
print("Prediction:", y_pred[0])
148-
149-
Ce pattern est compatible avec :
150-
151-
une API FastAPI (predict.py),
152-
153-
un batch scoring,
154-
155-
ou une intégration dans un pipeline plus large (Oasis, Streamlit, etc.).
156-
157-
=======
158-
>>>>>>> 7cca8880 (Update README.md and project files, add new datasets and notebooks)
1591
# 🏴‍☠️ Oasis Security – Crime Predictor
1602

1613
[![CI/CD](https://github.com/Data-Science-Designer-and-Developer/oasis-security/actions/workflows/ci-cd.yml/badge.svg)](https://github.com/Data-Science-Designer-and-Developer/oasis-security/actions)
1624
[![Docker](https://img.shields.io/badge/Docker-GHCR-blue)](https://ghcr.io/Data-Science-Designer-and-Developer)
1635
[![Model](https://img.shields.io/badge/R²-0.806-brightgreen)](https://github.com/Data-Science-Designer-and-Developer/oasis-security/blob/main/models/crime_predictor/models/crime_predictor.pkl)
1646

165-
**Production ML pipeline** forecasting French crime rates (per 100k) using data.gouv.fr police data.
166-
167-
## 🚀 Quick Start
168-
169-
```bash
170-
pip install -r models/crime_predictor/requirements.txt
171-
cd models/crime_predictor/src && python generate_model.py
172-
173-
Predict:
174-
175-
python
176-
import joblib
177-
model = joblib.load("../../models/crime_predictor.pkl")["model"]
178-
print(model.predict([[0.1,0.2,250,5]])) # ~287/100k
179-
180-
📁 Structure
181-
182-
text
183-
models/crime_predictor/
184-
├── src/ # model.py, generate_model.py
185-
├── models/ # crime_predictor.pkl (R²=0.806)
186-
├── mlruns/ # MLflow tracking
187-
├── tests/ # pytest ready
188-
└── requirements.txt
189-
190-
📊 Model
191-
192-
Data: data.gouv.fr (police stats 2016-2025)
193-
Features: year_sin, region_mean, ind_code
194-
R²: 0.806 (production stable)
195-
🔮 2030 Forecasts
196-
Region Crime Rate/100k
197-
IDF(11) VIOLENCES 387 🚨
198-
Paris CAMBRIOLE 245 ⚠️
199-
200-
<<<<<<< HEAD
201-
## 🚀 **Copie-colle → push → portfolio parfait**
202-
203-
```bash
204-
cd oasis-security-complete/
205-
cat > README.md << 'EOF'
206-
[Coller le markdown ci-dessus]
207-
EOF
208-
git add README.md
209-
git commit -m "📖 README pro senior DS"
210-
git push origin master
211-
**# Oasis Security – Crime Rate Predictor
212-
213-
[![Python](https://img.shields.io/badge/Python-3.11-blue?logo=python)](https://www.python.org/)
214-
[![License: MIT](https://img.shields.io/badge/License-MIT-green)](LICENSE)
215-
2167
A predictive model for crime rates in France (per 100,000 inhabitants), fully structured for production use.
2178
This repository demonstrates a **ML project with clear structure, documentation, modeling pipeline, and deployment readiness**.
218-
2199
---
22010

22111
## 🚀 Project Objectives
@@ -231,79 +21,61 @@ This repository demonstrates a **ML project with clear structure, documentation,
23121

23222
## 📁 Repository Structure
23323

234-
oasis-security/
235-
├── .github/ # GitHub workflows (CI/CD)
236-
├── data/ # Processed data files
237-
├── docs/ # Documentation & dashboards
238-
├── images/ # Visual assets & plots
239-
├── models/
240-
│ └── crime_predictor/
241-
│ ├── src/ # Source code for model
242-
│ ├── models/ # Serialized model (.pkl)
243-
│ ├── mlruns/ # MLflow tracking data
244-
│ ├── tests/ # Unit tests (optional)
245-
│ └── requirements.txt # Dependencies for this model
246-
├── notebooks/ # Exploration & analysis notebooks
247-
├── pipeline/ # Scripts for automation
248-
├── Dockerfile # Docker configuration
249-
├── LICENSE # License
250-
└── README.md # Project overview
24+
oasis-security/
25+
├── .github/ # GitHub workflows (CI/CD)
26+
├── data/ # Processed data files
27+
├── docs/ # Documentation & dashboards
28+
├── images/ # Visual assets & plots
29+
├── models/
30+
│ └── crime_predictor/
31+
│ ├── src/ # Source code for model
32+
│ ├── models/ # Serialized model (.pkl)
33+
│ ├── mlruns/ # MLflow tracking data
34+
│ ├── tests/ # Unit tests (optional)
35+
│ └── requirements.txt # Dependencies for this model
36+
├── notebooks/ # Exploration & analysis notebooks
37+
├── pipeline/ # Scripts for automation
38+
├── Dockerfile # Docker configuration
39+
├── LICENSE # License
40+
└── README.md # Project overview
25141

25242

25343
---
25444

25545
## 📊 Usage
25646

25747
1. Create & activate a virtual environment:
258-
```bash
25948
python3 -m venv .venv
26049
source .venv/bin/activate
26150

51+
26252
2. Install dependencies:
263-
'''bash
26453
pip install -r models/crime_predictor/requirements.txt
26554

26655
3. Run training:
267-
'''bash
26856
python models/crime_predictor/src/train.py
26957

27058
4. Start prediction API:
27159
python models/crime_predictor/src/predict.py
27260

61+
27362
📝 Contribution & CI/CD
27463

27564
This project is designed to be production ready with GitHub Actions workflows (tests & model builds).
27665
Contributions welcome 🌟
27766

278-
📜 License
279-
280-
MIT License
281-
282-
283-
---
284-
285-
### 3️⃣ Commit and push the changes
286-
287-
Après avoir modifié `README.md` avec le contenu ci‑dessus, exécute dans le terminal :
288-
289-
```bash
290-
git add README.md
291-
git commit -m "Update README to clear English structure"
292-
git push
293-
29467
🛠️ Tech Stack
29568

29669
Core: Python 3.13, scikit-learn, joblib
29770
Future: FastAPI, MLflow, Docker, GitHub Actions
29871
Data: data.gouv.fr (police/gendarmerie 2016-2025)
29972

73+
📜 License
74+
75+
MIT License
76+
30077
📝 Author
30178

30279
Frédéric Tellier – Data Scientist
303-
LinkedIn : https://www.linkedin.com/in/fr%C3%A9d%C3%A9ric-tellier-8a9170283/ | Portfolio : https://github.com/Dreipfelt/
304-
305-
Licence: MIT
306-
=======
307-
Author: Frédéric Tellier – Data Scientist
308-
License: MIT
309-
>>>>>>> 7cca8880 (Update README.md and project files, add new datasets and notebooks)
80+
LinkedIn : https://www.linkedin.com/in/fr%C3%A9d%C3%A9ric-tellier-8a9170283/
81+
| Portfolio : https://github.com/Dreipfelt/

0 commit comments

Comments
 (0)