KLEB38 commited on
Commit
9331de5
·
verified ·
1 Parent(s): 4aadca9

Upload folder using huggingface_hub

Browse files
.claude/session_2026-05-07_fastapi_setup.md ADDED
@@ -0,0 +1,290 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Session 2026-05-07 — FastAPI MLOps setup
2
+
3
+ > Point d'entrée pour reprendre le projet en session future. Capture le plan
4
+ > validé, les fichiers livrés, les déviations vs plan, et les prochaines étapes.
5
+
6
+ ## Contexte projet
7
+
8
+ OC_P8 — déploiement du modèle de scoring crédit (LightGBM, `lgbm_credit_scoring v2`)
9
+ entraîné dans OC_P6. Brief : API FastAPI + Docker + CI/CD + (étapes ultérieures :
10
+ drift monitoring + optimisation). Le feature engineering vivait dans
11
+ `notebooks/EDA.ipynb` et a été industrialisé.
12
+
13
+ ## Plan validé (extrait du plan complet)
14
+
15
+ Plan complet conservé : `C:\Users\Kevin\.claude\plans\tu-es-un-mlops-gleaming-shamir.md`
16
+
17
+ ### Décisions actées avec l'utilisateur
18
+
19
+ 1. **JSON input = toutes les 122 colonnes brutes d'application_train**
20
+ (pas un top-20). Raison : drift monitoring (étape 3 brief) a besoin
21
+ d'observer l'intégralité de l'espace input.
22
+
23
+ 2. **Deux cas à l'inférence** :
24
+ - **Cas 1 (client connu)** : `SK_ID_CURR` ∈ `features_store.parquet` →
25
+ lookup des ~600 features agrégées pré-calculées.
26
+ - **Cas 2 (client inconnu)** : template "no-history"
27
+ - Counts (`BURO_COUNT`, `INSTAL_COUNT`, `POS_COUNT`, `CC_COUNT`) → 0
28
+ - Autres agrégats (means, sums, etc.) → NaN
29
+ - Justification : LightGBM a été entraîné avec NaN comme **signal**
30
+ informatif ("pas d'historique"). Imputer une médiane crée du
31
+ train/serve skew.
32
+ - **Pas de SimpleImputer** — point clé sur lequel on s'est challengé.
33
+
34
+ 3. **Pydantic schema hand-crafted** avec ranges métier (FLAG ∈ {0,1},
35
+ DAYS_BIRTH ∈ [-25550, -6570] = 18-70 ans, etc.).
36
+
37
+ 4. **Threshold business 0.33** (lu de model_info.json, optimisé pour
38
+ `10*FN + FP`).
39
+
40
+ 5. **Séparation offline / runtime stricte** :
41
+ - `feature_engineering/` (offline) : 5 fonctions d'agrégation lourdes,
42
+ `merge_files()`. Pas importé par `api/`.
43
+ - `api/` (runtime) : juste la transformation app_train + ratios + lookup
44
+ parquet. Image Docker légère.
45
+
46
+ 6. **One-hot pitfall** résolu via `pd.Categorical(values, categories=KNOWN)`
47
+ avant `get_dummies()` — sinon une seule ligne ne génère qu'une colonne
48
+ par catégorielle au lieu de N. `models/app_train_categories.json` stocke
49
+ le vocabulaire exhaustif.
50
+
51
+ 7. **Binary mappings capturés** (`models/app_train_binary_mappings.json`)
52
+ pour reproduire exactement l'ordre `pd.factorize()` du training (ordre de
53
+ première apparition, pas alphabétique).
54
+
55
+ 8. **CI/CD** : GitHub Actions → pytest (gate 80%) → docker build → push
56
+ ghcr.io → deploy manuel HuggingFace Space.
57
+
58
+ ### Hors scope cette session
59
+
60
+ - Top-N SHAP contributors dans `PredictionResponse` (explicabilité)
61
+ - Étape 3 brief : logging structuré + Evidently drift + Streamlit dashboard
62
+ - Étape 4 brief : profiling, ONNX, optimisation latence
63
+
64
+ ---
65
+
66
+ ## Ce qui a été livré
67
+
68
+ ### Structure créée
69
+
70
+ ```
71
+ OC_P8/
72
+ ├── api/ ← runtime (bundled in Docker)
73
+ │ ├── __init__.py
74
+ │ ├── main.py ← FastAPI app + lifespan loading
75
+ │ ├── schemas.py ← Pydantic 121 champs (SK_ID_CURR + 120)
76
+ │ ├── predictor.py ← Singleton model + threshold
77
+ │ ├── inputs_transform.py ← Transform app_train (one-hot fix)
78
+ │ ├── ratios.py ← 5 ratios dérivés
79
+ │ ├── inference_assembler.py ← Branche connu/inconnu + reindex
80
+ │ └── settings.py ← Paths via env vars
81
+ ├── feature_engineering/ ← offline ONLY
82
+ │ ├── __init__.py
83
+ │ ├── aggregations.py ← 5 fonctions d'agrégation lourdes
84
+ │ └── orchestrator.py ← merge_files() + app_train_clean()
85
+ ├── scripts/
86
+ │ ├── build_feature_store.py ← NEW — génère parquet + 4 JSONs
87
+ │ ├── build_no_history_template.py ← NEW — template counts=0 / NaN
88
+ │ ├── export_model.py ← existant
89
+ │ ├── check_registry.py ← existant
90
+ │ └── smoke_test_model.py ← existant
91
+ ├── tests/
92
+ │ ├── conftest.py ← Fixtures synthétiques
93
+ │ ├── unit/
94
+ │ │ ├── test_ratios.py (5 tests)
95
+ │ │ ├── test_inputs_transform.py (6 tests)
96
+ │ │ ├── test_inference_assembler.py (6 tests)
97
+ │ │ ├── test_predictor.py (8 tests)
98
+ │ │ └── test_schemas.py (10 tests)
99
+ │ └── integration/
100
+ │ └── test_api.py (10 tests, FastAPI TestClient)
101
+ ├── models/ ← model.joblib + JSONs (committed)
102
+ ├── data/ ← features_store.parquet (gitignored)
103
+ ├── Dockerfile ← NEW
104
+ ├── .dockerignore ← NEW
105
+ ├── .gitignore ← MAJ �� exclut parquet, garde JSONs
106
+ ├── .github/workflows/ci.yml ← NEW — 3 jobs (test/build/deploy)
107
+ ├── pyproject.toml ← MAJ — fastapi, uvicorn, pyarrow,
108
+ │ pydantic + dev: pytest, pytest-cov,
109
+ │ httpx, ruff
110
+ └── README.md ← NEW — architecture + run instructions
111
+ ```
112
+
113
+ ### Tests : 45/45 passent, 97.9 % de couverture sur `api/`
114
+
115
+ ```
116
+ api/__init__.py 100%
117
+ api/inference_assembler.py 95%
118
+ api/inputs_transform.py 100%
119
+ api/main.py 89%
120
+ api/predictor.py 100%
121
+ api/ratios.py 100%
122
+ api/schemas.py 100%
123
+ api/settings.py 100%
124
+ TOTAL 98% (gate fixé à 80%)
125
+ ```
126
+
127
+ ### Artefacts à générer (TODO côté utilisateur)
128
+
129
+ Ces commandes n'ont **pas** été exécutées dans cette session car elles
130
+ nécessitent les données OC_P6 (~5 GB) :
131
+
132
+ ```powershell
133
+ uv run python scripts/build_feature_store.py
134
+ uv run python scripts/build_no_history_template.py
135
+ ```
136
+
137
+ Outputs attendus :
138
+ - `data/features_store.parquet` (~200 MB)
139
+ - `models/feature_names.json` (768 colonnes ordonnées)
140
+ - `models/app_train_columns.json` (122 cols meta)
141
+ - `models/app_train_categories.json` (vocab catégoriel)
142
+ - `models/app_train_binary_mappings.json` (codes factorize)
143
+ - `models/no_history_template.json` (template cas 2)
144
+
145
+ ---
146
+
147
+ ## Déviations vs plan
148
+
149
+ ### 1. Naming `feature_pipeline.py` → `inputs_transform.py`
150
+ **Plan** : `api/feature_pipeline.py` (8 fonctions)
151
+ **Réel** : `api/inputs_transform.py` + `api/ratios.py` séparément
152
+ **Raison** : suite à la simplification (les 5 fonctions d'agrégation lourdes
153
+ sont sorties de `api/`), le module runtime ne contient plus que la transfo
154
+ app_train + les ratios. Plus clair de les séparer.
155
+
156
+ ### 2. Ajout `app_train_binary_mappings.json` (pas dans le plan initial)
157
+ **Raison** : découvert pendant l'implémentation que `pd.factorize()` assigne
158
+ les codes par **ordre de première apparition** dans les données, pas
159
+ alphabétique. Coder en dur `{"M": 0, "F": 1}` était fragile. Le mapping est
160
+ maintenant capturé pendant `build_feature_store.py`.
161
+
162
+ ### 3. Schéma Pydantic = 121 champs au lieu de 122
163
+ **Plan** : 122 champs.
164
+ **Réel** : 121 champs (SK_ID_CURR + 120 features).
165
+ **Raison** : TARGET est exclu (c'est la cible à prédire, pas un input).
166
+ La colonne reste dans application_train.csv mais ne fait pas partie du JSON
167
+ input. Cohérent avec le brief.
168
+
169
+ ### 4. `apply_derived_ratios()` est dans le runtime, pas dans le orchestrator
170
+ **Plan** : ratios calculés dans `app_train_clean()` (offline).
171
+ **Réel** : duplication maîtrisée — le offline `app_train_clean()` les calcule
172
+ (pour le training) ET `api/ratios.py` les recalcule (pour l'inférence après
173
+ l'override JSON). C'était nécessaire pour que les ratios reflètent les inputs
174
+ JSON et non les valeurs stockées.
175
+
176
+ ### 5. Dockerfile sanity check ajouté
177
+ **Plan** : juste COPY + uvicorn.
178
+ **Réel** : ajouté un `RUN test -f ...` qui fait échouer le build si les
179
+ artefacts JSON/parquet sont manquants. Évite de découvrir le problème au
180
+ runtime.
181
+
182
+ ### 6. Coverage 97.9 % au lieu du minimum 80 %
183
+ **Plan** : ≥80 %.
184
+ **Réel** : dépassé sans effort particulier. Gate CI reste à 80 %.
185
+
186
+ ### Aucune déviation majeure
187
+ Le design (deux cas, no-history template, séparation offline/runtime,
188
+ one-hot fix, hand-crafted Pydantic) est exactement celui du plan validé.
189
+
190
+ ---
191
+
192
+ ## Prochaines étapes (à reprendre à la prochaine session)
193
+
194
+ ### Immédiat (à faire avant la prochaine session)
195
+ 1. **Générer les artefacts** :
196
+ ```powershell
197
+ uv run python scripts/build_feature_store.py
198
+ uv run python scripts/build_no_history_template.py
199
+ ```
200
+ 2. **Smoke test API** :
201
+ ```powershell
202
+ uv run uvicorn api.main:app --reload
203
+ # Puis tester via http://127.0.0.1:8000/docs
204
+ ```
205
+ 3. **Build Docker en local** :
206
+ ```powershell
207
+ docker build -t oc-p8-api .
208
+ docker run -p 8000:8000 oc-p8-api
209
+ ```
210
+ 4. **Push GitHub** pour déclencher CI.
211
+
212
+ ### À la prochaine session (Étape 3 brief — drift monitoring)
213
+
214
+ Décisions à prendre :
215
+ - **Stockage des logs prod** : Supabase (PostgreSQL) ? SQLite local ?
216
+ fichiers JSON ?
217
+ - **Drift detection** : Evidently AI vs NannyML ?
218
+ - **Dashboard** : Streamlit (suggéré dans le brief) ? HuggingFace Space
219
+ séparé ?
220
+ - **Logging structuré** : structlog ? loguru ? logging stdlib + JSON
221
+ formatter ?
222
+
223
+ Travaux à prévoir :
224
+ - Middleware FastAPI qui logue chaque requête (timestamp, inputs, output,
225
+ latency) dans le storage choisi
226
+ - Script `scripts/build_drift_report.py` qui prend les logs prod + le
227
+ training set comme reference, génère un rapport Evidently HTML
228
+ - Dashboard Streamlit qui affiche : distribution des scores, latence p50/p95,
229
+ taux d'erreur, top features driftées
230
+
231
+ ### Plus tard (Étape 4 brief — optimisation)
232
+ - Profiling cProfile / line_profiler sur `assemble()` + `predict()`
233
+ - Conversion ONNX du modèle si latence > seuil acceptable
234
+ - Quantification des poids (LightGBM le supporte mal directement → ONNX
235
+ intermédiaire)
236
+ - Comparaison avant/après en métriques + ROC-AUC
237
+
238
+ ### Améliorations API (priorité moyenne)
239
+ - **Top-N SHAP contributors** dans `PredictionResponse` :
240
+ `TreeExplainer.shap_values()` sur la prédiction → top-3 features
241
+ contributives → JSON enrichi pour l'agent commercial.
242
+ - **GET /clients/{sk_id_curr}** route debug/admin pour vérifier la présence
243
+ d'un client dans le store.
244
+ - **Authentification JWT** (pas demandée explicitement par le brief mais
245
+ attendu en prod).
246
+
247
+ ---
248
+
249
+ ## Choix techniques notables (pour future référence)
250
+
251
+ ### Modèle chargé via mlflow.pyfunc puis joblib.dump
252
+ - Le modèle exporté de OC_P6 est `MLflow PyFuncModel`
253
+ - `predictor._predict_proba()` gère 2 shapes : `(n,)` ou `(n, 2)`
254
+ - Si LightGBM natif est ré-extrait plus tard, refactor de `_predict_proba`
255
+ trivial.
256
+
257
+ ### Tests : isolation totale du code prod
258
+ - `conftest.py` génère synthetic_artefacts_dir avec mini-parquet, mini-JSONs,
259
+ FakeModel.joblib
260
+ - `patched_settings` fixture utilise `monkeypatch` pour pointer les env vars
261
+ vers le tmp_path
262
+ - L'app FastAPI est rechargée (`importlib.reload`) à chaque test integration
263
+ pour repartir sur des artefacts neufs.
264
+
265
+ ### Sécurité Pydantic
266
+ - `model_config = ConfigDict(extra="forbid")` rejette les champs inconnus
267
+ → couvre l'injection de données
268
+ - Tous les `Optional[float]` ont des bornes `Field(ge=, le=)` pour éviter
269
+ des outliers ridicules
270
+
271
+ ### Déploiement HuggingFace
272
+ - Le job `deploy` du workflow CI est en `workflow_dispatch` (manuel) pour
273
+ éviter les push accidentels
274
+ - Skip gracieux si `HF_TOKEN` / `HF_SPACE` ne sont pas configurés en
275
+ secrets — le workflow ne casse pas, il échoue silencieusement avec un log
276
+
277
+ ---
278
+
279
+ ## Bugs corrigés en route
280
+
281
+ 1. **Test `test_unknown_client_uses_no_history_template`** :
282
+ `np.isnan` ne fonctionnait pas car les `None` JSON restaient en object
283
+ dtype → fix dans `InferenceArtefacts.load` qui convertit None → np.nan.
284
+
285
+ 2. **Test `test_inf_values_replaced_with_nan`** :
286
+ `np.isinf(features.values)` échouait car le DataFrame contient des
287
+ `pd.Int64` (extension type) → fix : test ciblé sur les colonnes ratios.
288
+
289
+ 3. **Ruff warnings** : 4 unused imports / unused f-strings auto-fixés dans
290
+ scripts.
.claude/settings.local.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(uv add *)",
5
+ "Bash(python -c ' *)",
6
+ "Bash(uv run --active python -c ' *)",
7
+ "WebFetch(domain:github.com)"
8
+ ]
9
+ }
10
+ }
.dockerignore ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .git
2
+ .github
3
+ .venv
4
+ venv
5
+ __pycache__
6
+ *.pyc
7
+ *.pyo
8
+ .pytest_cache
9
+ .coverage
10
+ htmlcov
11
+ .ruff_cache
12
+ .mypy_cache
13
+
14
+ # Notebooks and exploration scripts not needed at runtime
15
+ notebooks/
16
+ scripts/
17
+ mlruns/
18
+ mlartifacts/
19
+ mlflow.db*
20
+
21
+ # Tests are run in CI, not bundled in the image
22
+ tests/
23
+
24
+ # Offline-only feature engineering code
25
+ feature_engineering/
26
+
27
+ # Local config
28
+ .env
29
+ .envrc
30
+ .vscode
31
+ .idea
32
+ *.swp
33
+
34
+ # Build artefacts
35
+ build/
36
+ dist/
37
+ *.egg-info/
.github/workflows/ci.yml ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+ workflow_dispatch: {}
9
+
10
+ env:
11
+ PYTHON_VERSION: "3.12"
12
+
13
+ jobs:
14
+ test:
15
+ name: pytest + coverage
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+ with:
20
+ lfs: true
21
+
22
+ - name: Set up Python
23
+ uses: actions/setup-python@v6
24
+ with:
25
+ python-version: ${{ env.PYTHON_VERSION }}
26
+
27
+ - name: Install uv
28
+ uses: astral-sh/setup-uv@v8.1.0
29
+ with:
30
+ version: "0.5.4"
31
+
32
+ - name: Install dependencies
33
+ run: uv sync --frozen
34
+
35
+ - name: Lint (ruff)
36
+ run: uv run ruff check api feature_engineering tests
37
+
38
+ - name: Run tests with coverage
39
+ run: |
40
+ uv run pytest \
41
+ --cov=api \
42
+ --cov-report=term-missing \
43
+ --cov-report=xml \
44
+ --cov-fail-under=80
45
+
46
+ - name: Upload coverage report
47
+ if: always()
48
+ uses: actions/upload-artifact@v7
49
+ with:
50
+ name: coverage-xml
51
+ path: coverage.xml
52
+ retention-days: 30
53
+
54
+ deploy:
55
+ name: Deploy to Hugging Face Space
56
+ needs: test
57
+ if: github.event_name == 'workflow_dispatch'
58
+ runs-on: ubuntu-latest
59
+ steps:
60
+ - uses: actions/checkout@v6
61
+ with:
62
+ fetch-depth: 0
63
+ lfs: true
64
+
65
+ - name: Push to Hugging Face Space
66
+ env:
67
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
68
+ run: |
69
+ pip install huggingface_hub
70
+ python - <<'EOF'
71
+ import os
72
+ from huggingface_hub import HfApi
73
+ api = HfApi(token=os.environ["HF_TOKEN"])
74
+ api.upload_folder(
75
+ folder_path=".",
76
+ repo_id="KLEB38/OC_P8",
77
+ repo_type="space",
78
+ ignore_patterns=[".git", ".github", ".venv", ".claude", "__pycache__", "*.pyc", "data/"],
79
+ )
80
+ EOF
.gitignore ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+
8
+ # Virtual environments
9
+ .venv/
10
+ venv/
11
+ env/
12
+ ENV/
13
+
14
+ # UV / Poetry
15
+ .uv/
16
+ .python-version
17
+
18
+ # Build / packaging
19
+ build/
20
+ dist/
21
+ *.egg-info/
22
+ *.egg
23
+ pip-wheel-metadata/
24
+
25
+ # Test / coverage
26
+ .pytest_cache/
27
+ .coverage
28
+ .coverage.*
29
+ htmlcov/
30
+ coverage.xml
31
+ *.cover
32
+
33
+ # Type checkers / linters
34
+ .mypy_cache/
35
+ .ruff_cache/
36
+ .dmypy.json
37
+
38
+ # Jupyter
39
+ .ipynb_checkpoints/
40
+ *.ipynb_checkpoints
41
+
42
+ # IDEs / OS
43
+ .vscode/
44
+ .idea/
45
+ *.swp
46
+ .DS_Store
47
+ Thumbs.db
48
+
49
+ # Environment files
50
+ .env
51
+ .env.local
52
+ .envrc
53
+
54
+ # MLflow local artefacts (kept in OC_P6, not commited here)
55
+ mlruns/
56
+ mlartifacts/
57
+ mlflow.db
58
+ mlflow.db.backup
59
+
60
+ # Large generated artefact — produced by scripts/build_feature_store.py.
61
+ # Too large for git (~100-300 MB); rebuild from the OC_P6 data when needed.
62
+ data/features_store.parquet
63
+
64
+ # The metadata JSONs (feature_names, app_train_columns, app_train_categories,
65
+ # app_train_binary_mappings, no_history_template) are intentionally COMMITTED:
66
+ # they are small (<100 KB total) and required by the Docker build. Regenerate
67
+ # them with: uv run python scripts/build_feature_store.py
68
+
69
+ # Project-local logs / scratch
70
+ logs/
71
+ *.log
72
+ scratch/
73
+ tmp/
Dockerfile CHANGED
@@ -1,20 +1,39 @@
1
- FROM python:3.13.5-slim
 
 
 
 
 
 
 
 
 
2
 
3
  WORKDIR /app
4
 
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- curl \
8
- git \
9
- && rm -rf /var/lib/apt/lists/*
10
 
11
- COPY requirements.txt ./
12
- COPY src/ ./src/
 
 
13
 
14
- RUN pip3 install -r requirements.txt
 
 
 
 
 
 
 
15
 
16
- EXPOSE 8501
17
 
18
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
 
 
19
 
20
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ # syntax=docker/dockerfile:1
2
+ FROM python:3.12-slim
3
+
4
+ ENV PYTHONDONTWRITEBYTECODE=1 \
5
+ PYTHONUNBUFFERED=1 \
6
+ UV_PROJECT_ENVIRONMENT=/opt/venv \
7
+ PATH=/opt/venv/bin:$PATH
8
+
9
+ # UV gives reproducible installs from uv.lock and is faster than pip.
10
+ COPY --from=ghcr.io/astral-sh/uv:0.5.4 /uv /usr/local/bin/uv
11
 
12
  WORKDIR /app
13
 
14
+ # Resolve runtime deps first so the layer is cached when only source code
15
+ # changes.
16
+ COPY pyproject.toml uv.lock ./
17
+ RUN uv sync --frozen --no-dev --no-install-project
 
18
 
19
+ # Application code + serialized artefacts.
20
+ COPY api/ ./api/
21
+ COPY models/ ./models/
22
+ COPY data/ ./data/
23
 
24
+ # Sanity: fail fast at build time if the artefacts the API needs are missing.
25
+ RUN test -f models/model.joblib \
26
+ && test -f models/feature_names.json \
27
+ && test -f models/app_train_categories.json \
28
+ && test -f models/app_train_binary_mappings.json \
29
+ && test -f models/no_history_template.json \
30
+ && test -f data/features_store.parquet \
31
+ && echo "All runtime artefacts present."
32
 
33
+ EXPOSE 7860
34
 
35
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
36
+ CMD python -c "import urllib.request, sys; \
37
+ sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:7860/health').status == 200 else 1)"
38
 
39
+ CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,19 +1,398 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- title: OC P8
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: red
6
- sdk: docker
7
- app_port: 8501
8
- tags:
9
- - streamlit
10
- pinned: false
11
- short_description: Streamlit template space
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
 
14
- # Welcome to Streamlit!
15
 
16
- Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
 
 
 
 
 
 
 
 
 
 
17
 
18
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
19
- forums](https://discuss.streamlit.io).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [![Python][python-badge]][python-url]
2
+ [![FastAPI][fastapi-badge]][fastapi-url]
3
+ [![CI][ci-badge]][ci-url]
4
+ [![uv][uv-badge]][uv-url]
5
+ [![License: Internal][license-badge]](#license)
6
+
7
+ <br />
8
+ <div align="center">
9
+ <h1 align="center">OC P8 — Credit Scoring API</h1>
10
+ <p align="center">
11
+ Production-grade FastAPI wrapper around the XGBoost credit scoring model
12
+ trained in OC_P6. Built for <em>Prêt à Dépenser</em>'s Crédit Express department:
13
+ real-time default risk prediction for loan officers.
14
+ <br />
15
+ <a href="http://localhost:8000/docs"><strong>Swagger UI (local) »</strong></a>
16
+ <br />
17
+ <br />
18
+ <a href="#getting-started">Quick Start</a>
19
+ ·
20
+ <a href="#cicd-pipeline">CI/CD</a>
21
+ ·
22
+ <a href="#roadmap">Roadmap</a>
23
+ </p>
24
+ </div>
25
+
26
+ ---
27
+
28
+ ## Table of Contents
29
+
30
+ - [About The Project](#about-the-project)
31
+ - [Built With](#built-with)
32
+ - [Getting Started](#getting-started)
33
+ - [Prerequisites](#prerequisites)
34
+ - [One-time offline setup](#one-time-offline-setup)
35
+ - [Run the API](#run-the-api)
36
+ - [Tests](#tests)
37
+ - [Usage](#usage)
38
+ - [Architecture](#architecture)
39
+ - [CI/CD Pipeline](#cicd-pipeline)
40
+ - [Jobs overview](#jobs-overview)
41
+ - [Job: test](#job-test)
42
+ - [Job: deploy](#job-deploy)
43
+ - [Required secrets](#required-secrets)
44
+ - [Docker](#docker)
45
+ - [Project Layout](#project-layout)
46
+ - [Roadmap](#roadmap)
47
+ - [License](#license)
48
+
49
+ ---
50
+
51
+ ## About The Project
52
+
53
+ The **Credit Scoring API** exposes a single `POST /predict` endpoint. Given a loan application (`SK_ID_CURR` + 120 raw `application_train` fields), it returns:
54
+
55
+ - `probability_default` — model score between 0 and 1
56
+ - `decision` — `true` (loan refused) if `proba ≥ 0.33`, `false` (loan granted) otherwise
57
+ - `threshold`, `model_version`, `client_known` — explainability metadata
58
+
59
+ The threshold **0.33** is optimised for an asymmetric cost function (10 × false negatives + false positives), meaning the model is intentionally conservative: missing a bad borrower costs 10× more than wrongly refusing a good one.
60
+
61
+ ---
62
+
63
+ ## Built With
64
+
65
+ [![Python][python-badge]][python-url]
66
+ [![FastAPI][fastapi-badge]][fastapi-url]
67
+ [![XGBoost][xgboost-badge]][xgboost-url]
68
+ [![uv][uv-badge]][uv-url]
69
+ [![Docker][docker-badge]][docker-url]
70
+ [![GitHub Actions][gha-badge]][gha-url]
71
+
72
+ ---
73
+
74
+ ## Getting Started
75
+
76
+ ### Prerequisites
77
+
78
+ | Tool | Version | Install |
79
+ |------|---------|---------|
80
+ | Python | 3.12 | [python.org](https://www.python.org/downloads/) |
81
+ | uv | latest | `pip install uv` |
82
+ | Docker | any | [docs.docker.com](https://docs.docker.com/get-docker/) |
83
+ | OC_P6 data | — | `C:/Users/Kevin/projects/OC_P6/data/` |
84
+
85
+ ### One-time offline setup
86
+
87
+ Generate all runtime artefacts (feature store parquet + metadata JSONs):
88
+
89
+ ```powershell
90
+ uv sync
91
+ uv run python scripts/build_feature_store.py
92
+ uv run python scripts/build_no_history_template.py
93
+ ```
94
+
95
+ This creates:
96
+
97
+ | Artefact | Size | Description |
98
+ |----------|------|-------------|
99
+ | `data/features_store.parquet` | ~200 MB | Pre-computed bureau / prev / POS / CC / install aggregates |
100
+ | `models/feature_names.json` | ~30 KB | Canonical 768-column order |
101
+ | `models/app_train_columns.json` | ~50 KB | Spec for the 122 raw input columns |
102
+ | `models/app_train_categories.json` | ~5 KB | Categorical vocabulary for one-hot encoding |
103
+ | `models/app_train_binary_mappings.json` | <1 KB | Factorize codes for binary columns |
104
+ | `models/no_history_template.json` | ~30 KB | Default values for unknown clients |
105
+
106
+ ### Run the API
107
+
108
+ ```powershell
109
+ uv run uvicorn api.main:app --reload
110
+ ```
111
+
112
+ | Endpoint | URL |
113
+ |----------|-----|
114
+ | Swagger UI | http://127.0.0.1:8000/docs |
115
+ | Health check | http://127.0.0.1:8000/health |
116
+ | Model info | http://127.0.0.1:8000/model/info |
117
+
118
+ ### Tests
119
+
120
+ ```powershell
121
+ # All tests + coverage report
122
+ uv run pytest --cov=api --cov-report=term-missing
123
+
124
+ # Unit tests only
125
+ uv run pytest tests/unit/
126
+
127
+ # Integration tests only
128
+ uv run pytest tests/integration/
129
+
130
+ # A specific module
131
+ uv run pytest tests/unit/test_ratios.py -v
132
+ ```
133
+
134
+ Current coverage: **98%** across 45 tests. Coverage gate enforced at **80%** in CI.
135
+
136
+ #### Test strategy
137
+
138
+ All tests run **without the real 5 GB training data**. The `conftest.py` fixture `synthetic_artefacts_dir` generates a complete but minimal artefact set in `tmp_path` at test time:
139
+
140
+ - A 2-row `features_store.parquet` (clients 100002 and 100003)
141
+ - Minimal JSON vocabularies (13 categorical columns, 3 binary columns)
142
+ - A `FakeModel` whose probability is deterministically driven by `AMT_INCOME_TOTAL / AMT_CREDIT`, so tests can exercise both `GRANTED` and `REFUSED` branches reliably
143
+ - A realistic 122-field `VALID_PAYLOAD` dict reused across all test modules
144
+
145
+ The `patched_settings` fixture redirects all `api.settings` paths to `tmp_path` via env vars + `importlib.reload()`, so no monkey-patching of internal state is needed.
146
+
147
+ #### Unit tests
148
+
149
+ | File | Module tested | What is verified |
150
+ |------|--------------|-----------------|
151
+ | `test_ratios.py` | `api/ratios.py` | 5 ratio formulas (known values, division-by-zero → NaN, NaN propagation, input immutability) |
152
+ | `test_inputs_transform.py` | `api/inputs_transform.py` | One-hot fix (all training categories emitted on a single row), binary factorization, `DAYS_EMPLOYED` sentinel → NaN, unknown category → all-zero |
153
+ | `test_predictor.py` | `api/predictor.py` | Threshold loaded from `model_info.json`, fallback to default, GRANTED/REFUSED boundary at exactly `threshold`, 1D and 3D prediction shape handling |
154
+ | `test_inference_assembler.py` | `api/inference_assembler.py` | Known client pulls parquet aggregates, unknown client uses template (counts=0, NaN), column order matches `feature_names`, inf values scrubbed to NaN |
155
+ | `test_schemas.py` | `api/schemas.py` | Pydantic range guards: negative income rejected, age < 18 and > 70 rejected, unknown contract type rejected, extra fields rejected, optional fields accept `null` |
156
+
157
+ #### Integration tests
158
+
159
+ `tests/integration/test_api.py` boots the full FastAPI app via `TestClient` with synthetic artefacts:
160
+
161
+ | Test | What is verified |
162
+ |------|-----------------|
163
+ | `test_health_endpoint` | `GET /health` returns 200 with `model_version` |
164
+ | `test_swagger_docs_available` | `GET /docs` returns 200 (brief requirement) |
165
+ | `test_openapi_schema` | `/openapi.json` exposes the `/predict` path |
166
+ | `test_model_info_endpoint` | `GET /model/info` returns threshold, version, n_features |
167
+ | `test_predict_known_client` | Full predict flow for a client in the feature store: `client_known=true`, decision in `{GRANTED, REFUSED}`, proba ∈ [0, 1] |
168
+ | `test_predict_unknown_client` | Unknown `SK_ID_CURR` → `client_known=false`, no crash |
169
+ | `test_predict_rejects_negative_income` | HTTP 422 on invalid input (Pydantic guard) |
170
+ | `test_predict_rejects_missing_required_field` | HTTP 422 when `DAYS_BIRTH` is absent |
171
+ | `test_predict_rejects_extra_field` | HTTP 422 on field injection attempt |
172
+ | `test_predict_rejects_unknown_contract_type` | HTTP 422 on out-of-vocabulary enum value |
173
+
174
+ ---
175
+
176
+ ## Usage
177
+
178
+ Send a POST request to `/predict` with a JSON body containing `SK_ID_CURR` and the 120 `application_train` fields:
179
+
180
+ ```powershell
181
+ curl -X POST http://127.0.0.1:8000/predict `
182
+ -H "Content-Type: application/json" `
183
+ -d '{"SK_ID_CURR": 100001, "AMT_INCOME_TOTAL": 202500.0, ...}'
184
+ ```
185
+
186
+ Example response:
187
+
188
+ ```json
189
+ {
190
+ "sk_id_curr": 100001,
191
+ "probability_default": 0.1523,
192
+ "decision": false,
193
+ "threshold": 0.33,
194
+ "model_version": "xgb-v1.0",
195
+ "client_known": true
196
+ }
197
+ ```
198
+
199
+ `decision: false` = loan **granted** · `decision: true` = loan **refused**
200
+
201
+ You can also use the interactive **Swagger UI** at `/docs` → `POST /predict` → **Try it out**.
202
+
203
+ ---
204
+
205
+ ## Architecture
206
+
207
+ ```
208
+ JSON {SK_ID_CURR + 120 raw application_train fields}
209
+ ▼
210
+ Pydantic validation (122 ranged fields)
211
+ ▼
212
+ ┌─────────────────────────┐
213
+ │ Known SK_ID_CURR ? │
214
+ └────┬────────────────┬───┘
215
+ yes ▼ no ▼
216
+ feature_store no_history_template
217
+ parquet lookup (counts=0, NaN)
218
+ │ │
219
+ └────────┬─────────┘
220
+ ▼
221
+ transform app_train inputs (factorize + one-hot
222
+ with training categories) + 5 derived ratios
223
+ ▼
224
+ reindex to feature_names → 768 cols
225
+ ▼
226
+ model.predict_proba()[:, 1]
227
+ ▼
228
+ decision = proba ≥ 0.33 (business threshold optimised
229
+ for 10*FN + FP cost)
230
+ ▼
231
+ {sk_id_curr, probability_default, decision,
232
+ threshold, model_version, client_known}
233
+ ```
234
+
235
+ **Two-case inference flow:**
236
+
237
+ | Case | Trigger | Aggregate source |
238
+ |------|---------|-----------------|
239
+ | **Known client** | `SK_ID_CURR` found in `features_store.parquet` | Pre-computed bureau / prev / POS / CC / install |
240
+ | **Unknown client** | `SK_ID_CURR` not found | `no_history_template.json` (counts=0, rest NaN) |
241
+
242
+ The unknown-client path preserves XGBoost's training-time NaN signal ("no historical data") rather than imputing fictitious medians.
243
+
244
+ ---
245
+
246
+ ## CI/CD Pipeline
247
+
248
+ The pipeline is defined in [`.github/workflows/ci.yml`](.github/workflows/ci.yml) and runs on **GitHub Actions**. It is composed of two sequential jobs.
249
+
250
+ ```
251
+ push to main / pull request
252
+ │
253
+ ▼
254
+ ┌─────────┐
255
+ │ test │ ← runs on every push and PR
256
+ └────┬────┘
257
+ │ success + workflow_dispatch
258
+ ▼
259
+ ┌─────────┐
260
+ │ deploy │ ← manual trigger only
261
+ └─────────┘
262
+ ```
263
+
264
+ ### Jobs overview
265
+
266
+ | Job | Trigger | Runner | Purpose |
267
+ |-----|---------|--------|---------|
268
+ | `test` | Every push / PR to `main` | `ubuntu-latest` | Lint + tests + coverage |
269
+ | `deploy` | Manual `workflow_dispatch` (after `test`) | `ubuntu-latest` | Push repo to Hugging Face Space |
270
+
271
+ ---
272
+
273
+ ### Job: test
274
+
275
+ **Trigger:** every `push` and `pull_request` targeting `main`.
276
+
277
+ **Steps:**
278
+
279
+ 1. **Checkout** — fetches the full source tree (`actions/checkout@v6`)
280
+ 2. **Set up Python 3.12** — installs the exact Python version (`actions/setup-python@v6`)
281
+ 3. **Install uv** — installs the uv package manager (`astral-sh/setup-uv@v8.1.0`)
282
+ 4. **Install dependencies** — `uv sync --frozen` (respects the lockfile, no version drift)
283
+ 5. **Lint (ruff)** — `uv run ruff check api feature_engineering tests`
284
+ - Fails fast if any style/quality issue is found
285
+ - Checked directories: `api/`, `feature_engineering/`, `tests/`
286
+ 6. **Run tests with coverage** — `uv run pytest --cov=api --cov-report=xml --cov-fail-under=80`
287
+ - Minimum coverage gate: **80%** — pipeline fails below this threshold
288
+ - Generates `coverage.xml` for downstream reporting
289
+ 7. **Upload coverage artifact** — uploads `coverage.xml` with 30-day retention (always runs, even if tests fail)
290
+
291
+ **Failure policy:** any failing step blocks the `deploy` job downstream.
292
+
293
+ ---
294
+
295
+ ### Job: deploy
296
+
297
+ **Trigger:** manual via **Actions → Run workflow** (`workflow_dispatch`). Requires `test` to have succeeded.
298
+
299
+ **Steps:**
300
+
301
+ 1. **Checkout** — full history (`fetch-depth: 0`) so git can push all commits
302
+ 2. **Push to Hugging Face Space** — force-pushes the `main` branch to the HF Space remote
303
+ Hugging Face Spaces automatically rebuilds the Docker container from the `Dockerfile` when the branch is updated.
304
+
305
+ ---
306
+
307
+ ### Required secrets
308
+
309
+ Configure these in **GitHub → Settings → Secrets and variables → Actions**:
310
+
311
+ | Secret | Required for | Description |
312
+ |--------|-------------|-------------|
313
+ | `HF_TOKEN` | `deploy` | Hugging Face write token ([huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)) |
314
+
315
+ ---
316
+
317
+ ## Docker
318
+
319
+ Build and run locally:
320
+
321
+ ```powershell
322
+ docker build -t oc-p8-api .
323
+ docker run -p 7860:7860 oc-p8-api
324
+ curl http://127.0.0.1:8000/health
325
+ ```
326
+
327
+ The `Dockerfile` validates that all runtime artefacts are present at build time — if you forgot to run `build_feature_store.py`, the build fails fast with a clear message.
328
+
329
  ---
330
+
331
+ ## Project Layout
332
+
333
+ ```
334
+ api/ # Runtime — bundled in Docker image
335
+ main.py # FastAPI app + lifespan model loading
336
+ predictor.py # Model + threshold wrapper
337
+ schemas.py # Pydantic — 122 hand-crafted fields with ranges
338
+ inputs_transform.py # Single-row app_train transform (one-hot fix)
339
+ ratios.py # 5 derived ratio formulas
340
+ inference_assembler.py # Branch known/unknown + reindex to 768 cols
341
+ settings.py # Paths resolved from env vars with defaults
342
+
343
+ feature_engineering/ # Offline ONLY — not imported by the API
344
+ aggregations.py # 5 aggregation funcs (bureau, prev, POS, CC, install)
345
+ orchestrator.py # merge_files() — full training dataframe build
346
+
347
+ scripts/ # Offline maintenance scripts
348
+ build_feature_store.py
349
+ build_no_history_template.py
350
+ export_model.py # Imports model.joblib from OC_P6 MLflow registry
351
+ smoke_test_model.py
352
+ check_registry.py
353
+
354
+ tests/
355
+ conftest.py # Synthetic fixtures — no real data needed
356
+ unit/ # Per-module unit tests
357
+ integration/ # FastAPI TestClient end-to-end tests
358
+
359
+ models/ # model.joblib + JSON metadata (committed to git)
360
+ data/ # features_store.parquet (gitignored — too large)
361
+ .github/workflows/
362
+ ci.yml # 3-job CI/CD pipeline
363
+ Dockerfile
364
+ pyproject.toml
365
+ ```
366
+
367
  ---
368
 
369
+ ## Roadmap
370
 
371
+ - [ ] **Étape 3** — Structured request logging + Evidently AI drift report + Streamlit monitoring dashboard
372
+ - [ ] **Étape 4** — Profiling, ONNX export, latency optimisation
373
+ - [ ] Top-N SHAP contributors in `PredictionResponse` for loan officer explainability
374
+
375
+ ---
376
+
377
+ ## License
378
+
379
+ Internal project — Prêt à Dépenser MLOps formation OpenClassrooms.
380
+
381
+ ---
382
 
383
+ <!-- BADGE LINKS -->
384
+ [python-badge]: https://img.shields.io/badge/Python-3.12-3776AB?style=for-the-badge&logo=python&logoColor=white
385
+ [python-url]: https://www.python.org/
386
+ [fastapi-badge]: https://img.shields.io/badge/FastAPI-0.115-009688?style=for-the-badge&logo=fastapi&logoColor=white
387
+ [fastapi-url]: https://fastapi.tiangolo.com/
388
+ [xgboost-badge]: https://img.shields.io/badge/XGBoost-2.x-F7931E?style=for-the-badge
389
+ [xgboost-url]: https://xgboost.readthedocs.io/
390
+ [uv-badge]: https://img.shields.io/badge/uv-package%20manager-DE5FE9?style=for-the-badge
391
+ [uv-url]: https://docs.astral.sh/uv/
392
+ [docker-badge]: https://img.shields.io/badge/Docker-container-2496ED?style=for-the-badge&logo=docker&logoColor=white
393
+ [docker-url]: https://www.docker.com/
394
+ [gha-badge]: https://img.shields.io/badge/GitHub%20Actions-CI%2FCD-2088FF?style=for-the-badge&logo=githubactions&logoColor=white
395
+ [gha-url]: https://github.com/features/actions
396
+ [ci-badge]: https://img.shields.io/github/actions/workflow/status/KLEB38/OC_P8/ci.yml?branch=main&style=for-the-badge&label=CI
397
+ [ci-url]: https://github.com/KLEB38/OC_P8/actions
398
+ [license-badge]: https://img.shields.io/badge/license-internal-lightgrey?style=for-the-badge
api/__init__.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ """Runtime FastAPI application for the credit scoring model.
2
+
3
+ Light, focused module: only the transformations needed to turn a single
4
+ JSON payload into a 768-feature row the model can score. Heavy aggregation
5
+ is precomputed offline by feature_engineering/.
6
+ """
api/inference_assembler.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Build the 768-column feature row consumed by the model.
2
+
3
+ The flow:
4
+ 1. Take the raw JSON inputs and apply app_train transforms (factorize +
5
+ one-hot using the training categories) and the 5 derived ratios.
6
+ 2. Look up the auxiliary aggregates either from the parquet feature store
7
+ (Case 1: known SK_ID_CURR) or from the no-history template (Case 2).
8
+ 3. Concatenate horizontally and reindex to feature_names so the column
9
+ order matches what the model was trained on.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ from dataclasses import dataclass
16
+ from pathlib import Path
17
+ from typing import Any
18
+
19
+ import numpy as np
20
+ import pandas as pd
21
+
22
+ from api.inputs_transform import (
23
+ load_binary_mappings,
24
+ load_categories,
25
+ transform_app_train_inputs,
26
+ )
27
+ from api.ratios import apply_derived_ratios
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class InferenceArtefacts:
32
+ """Read-only container for everything needed to assemble a feature row."""
33
+
34
+ feature_names: list[str]
35
+ known_categories: dict[str, list[str]]
36
+ binary_mappings: dict[str, dict[str, int]]
37
+ no_history_template: dict[str, float | int | None]
38
+ feature_store: pd.DataFrame # indexed by SK_ID_CURR
39
+
40
+ @classmethod
41
+ def load(
42
+ cls,
43
+ feature_names_path: Path,
44
+ categories_path: Path,
45
+ binary_mappings_path: Path,
46
+ no_history_template_path: Path,
47
+ feature_store_path: Path,
48
+ ) -> "InferenceArtefacts":
49
+ feature_names = json.loads(feature_names_path.read_text())
50
+ known_categories = load_categories(categories_path)
51
+ binary_mappings = load_binary_mappings(binary_mappings_path)
52
+ # JSON null → Python None → np.nan, so LightGBM sees the same NaN signal
53
+ # it learned during training rather than an object-dtype None.
54
+ raw_template = json.loads(no_history_template_path.read_text())
55
+ no_history_template = {
56
+ k: (np.nan if v is None else v) for k, v in raw_template.items()
57
+ }
58
+
59
+ feature_store = pd.read_parquet(feature_store_path)
60
+ if feature_store.index.name != "SK_ID_CURR":
61
+ # Parquet stores SK_ID_CURR either as index or column; normalise.
62
+ if "SK_ID_CURR" in feature_store.columns:
63
+ feature_store = feature_store.set_index("SK_ID_CURR")
64
+
65
+ return cls(
66
+ feature_names=feature_names,
67
+ known_categories=known_categories,
68
+ binary_mappings=binary_mappings,
69
+ no_history_template=no_history_template,
70
+ feature_store=feature_store,
71
+ )
72
+
73
+
74
+ def assemble(
75
+ raw_inputs: dict[str, Any],
76
+ sk_id_curr: int,
77
+ artefacts: InferenceArtefacts,
78
+ ) -> tuple[pd.DataFrame, bool]:
79
+ """Build a 1×768 DataFrame ready for model.predict().
80
+
81
+ Returns (features, client_known).
82
+ """
83
+ # 1. App_train portion — always reconstructed from the JSON payload.
84
+ app_part = transform_app_train_inputs(
85
+ raw_inputs,
86
+ known_categories=artefacts.known_categories,
87
+ binary_mappings=artefacts.binary_mappings,
88
+ )
89
+ app_part = apply_derived_ratios(app_part)
90
+
91
+ # 2. Aggregate portion — lookup or template.
92
+ if sk_id_curr in artefacts.feature_store.index:
93
+ agg_part = artefacts.feature_store.loc[[sk_id_curr]].copy()
94
+ agg_part.reset_index(drop=True, inplace=True)
95
+ client_known = True
96
+ else:
97
+ agg_part = pd.DataFrame([artefacts.no_history_template])
98
+ client_known = False
99
+
100
+ # 3. Combine and align to the model's expected column order.
101
+ combined = pd.concat(
102
+ [app_part.reset_index(drop=True), agg_part.reset_index(drop=True)],
103
+ axis=1,
104
+ )
105
+
106
+ # Some columns may appear in both halves (e.g. duplicated SK_ID_CURR if
107
+ # not stripped). Keep the first occurrence.
108
+ combined = combined.loc[:, ~combined.columns.duplicated()]
109
+
110
+ aligned = combined.reindex(columns=artefacts.feature_names)
111
+ aligned = aligned.replace([np.inf, -np.inf], np.nan)
112
+
113
+ return aligned, client_known
api/inputs_transform.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Single-row transformation of raw application_train inputs.
2
+
3
+ Reproduces the engineering applied by feature_engineering.orchestrator
4
+ :: app_train_clean() but designed for one row at inference time.
5
+
6
+ The crucial detail: pd.get_dummies() on a single row only emits columns
7
+ for values actually present, so we feed it pd.Categorical(values,
8
+ categories=KNOWN) to guarantee that every category seen during training
9
+ yields a column — even when the value is absent from this particular request.
10
+
11
+ KNOWN_CATEGORIES is loaded from models/app_train_categories.json.
12
+ BINARY_MAPPINGS is loaded from models/app_train_binary_mappings.json
13
+ (captures the actual pd.factorize() codes used at training).
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ from pathlib import Path
20
+ from typing import Any
21
+
22
+ import numpy as np
23
+ import pandas as pd
24
+
25
+ BINARY_COLUMNS = ("CODE_GENDER", "FLAG_OWN_CAR", "FLAG_OWN_REALTY")
26
+ DAYS_EMPLOYED_SENTINEL = 365243
27
+
28
+
29
+ def load_categories(path: Path) -> dict[str, list[str]]:
30
+ """Load the {column: [training categories]} map for multi-valued cats."""
31
+ return json.loads(path.read_text())
32
+
33
+
34
+ def load_binary_mappings(path: Path) -> dict[str, dict[str, int]]:
35
+ """Load the {column: {value: code}} factorize mapping captured at training."""
36
+ return json.loads(path.read_text())
37
+
38
+
39
+ def transform_app_train_inputs(
40
+ raw: dict[str, Any],
41
+ known_categories: dict[str, list[str]],
42
+ binary_mappings: dict[str, dict[str, int]],
43
+ ) -> pd.DataFrame:
44
+ """Convert a raw JSON payload (dict) to a one-row DataFrame matching the
45
+ training-time output of app_train_clean(), excluding TARGET.
46
+
47
+ Output is missing the 5 derived ratios — pipe through
48
+ api.ratios.apply_derived_ratios() afterward.
49
+ """
50
+ df = pd.DataFrame([raw])
51
+
52
+ for col in BINARY_COLUMNS:
53
+ if col in df.columns:
54
+ df[col] = df[col].map(binary_mappings[col]).astype("Int64")
55
+
56
+ multi_cat_cols = [
57
+ c for c in known_categories if c not in BINARY_COLUMNS and c in df.columns
58
+ ]
59
+ for col in multi_cat_cols:
60
+ df[col] = pd.Categorical(df[col], categories=known_categories[col])
61
+
62
+ df = pd.get_dummies(df, columns=multi_cat_cols, dummy_na=False)
63
+
64
+ if "DAYS_EMPLOYED" in df.columns:
65
+ df["DAYS_EMPLOYED"] = df["DAYS_EMPLOYED"].replace(
66
+ DAYS_EMPLOYED_SENTINEL, np.nan
67
+ )
68
+
69
+ return df
api/main.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """FastAPI application entrypoint.
2
+
3
+ Loads the model and feature artefacts once at startup (lifespan), then
4
+ serves them to every request without ever reloading — per the brief's
5
+ critical guideline.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ import logging
12
+ from contextlib import asynccontextmanager
13
+
14
+ from fastapi import FastAPI, HTTPException, Request, status
15
+ from fastapi.responses import JSONResponse
16
+
17
+ from api import settings
18
+ from api.inference_assembler import InferenceArtefacts, assemble
19
+ from api.predictor import CreditScoringPredictor
20
+ from api.schemas import (
21
+ HealthResponse,
22
+ ModelInfoResponse,
23
+ PredictionRequest,
24
+ PredictionResponse,
25
+ )
26
+
27
+ logger = logging.getLogger(__name__)
28
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s")
29
+
30
+
31
+ @asynccontextmanager
32
+ async def lifespan(app: FastAPI):
33
+ """Load heavy artefacts once and attach them to app.state."""
34
+ logger.info("Loading model from %s", settings.MODEL_PATH)
35
+ app.state.predictor = CreditScoringPredictor.load(
36
+ model_path=settings.MODEL_PATH,
37
+ model_info_path=settings.MODEL_INFO_PATH,
38
+ default_threshold=settings.DEFAULT_THRESHOLD,
39
+ )
40
+ logger.info(
41
+ "Predictor ready: version=%s threshold=%.4f",
42
+ app.state.predictor.model_version,
43
+ app.state.predictor.threshold,
44
+ )
45
+
46
+ logger.info("Loading inference artefacts...")
47
+ app.state.artefacts = InferenceArtefacts.load(
48
+ feature_names_path=settings.FEATURE_NAMES_PATH,
49
+ categories_path=settings.APP_TRAIN_CATEGORIES_PATH,
50
+ binary_mappings_path=settings.APP_TRAIN_BINARY_MAPPINGS_PATH,
51
+ no_history_template_path=settings.NO_HISTORY_TEMPLATE_PATH,
52
+ feature_store_path=settings.FEATURE_STORE_PATH,
53
+ )
54
+ logger.info(
55
+ "Artefacts ready: %d feature_names, feature_store=%d clients",
56
+ len(app.state.artefacts.feature_names),
57
+ len(app.state.artefacts.feature_store),
58
+ )
59
+
60
+ # Cache model_info for the /model/info route.
61
+ app.state.model_info = json.loads(settings.MODEL_INFO_PATH.read_text())
62
+
63
+ yield
64
+
65
+
66
+ app = FastAPI(
67
+ title="Credit Scoring API",
68
+ description=(
69
+ "Real-time credit default prediction for Prêt à Dépenser. "
70
+ "Wraps a LightGBM model with business threshold 10*FN + FP."
71
+ ),
72
+ version="1.0.0",
73
+ lifespan=lifespan,
74
+ )
75
+
76
+
77
+ @app.exception_handler(Exception)
78
+ async def unhandled_exception_handler(request: Request, exc: Exception) -> JSONResponse:
79
+ """JSON error envelope for unexpected failures, structured for log shipping."""
80
+ logger.exception("Unhandled error on %s %s", request.method, request.url.path)
81
+ return JSONResponse(
82
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
83
+ content={"detail": "Internal server error", "type": exc.__class__.__name__},
84
+ )
85
+
86
+
87
+
88
+ @app.get("/") # La page d'accueil
89
+ async def read_root():
90
+ return {"message": "Welcome to the CREDIT DEFAULT predictor API for Prêt à Dépenser"}
91
+
92
+
93
+ @app.get("/health", response_model=HealthResponse, tags=["meta"])
94
+ async def health(request: Request) -> HealthResponse:
95
+ return HealthResponse(status="ok", model_version=request.app.state.predictor.model_version)
96
+
97
+
98
+ @app.get("/model/info", response_model=ModelInfoResponse, tags=["meta"])
99
+ async def model_info(request: Request) -> ModelInfoResponse:
100
+ info = request.app.state.model_info
101
+ return ModelInfoResponse(
102
+ model_name=info.get("model_name", "lgbm_credit_scoring"),
103
+ version=str(info.get("version", "unknown")),
104
+ threshold=request.app.state.predictor.threshold,
105
+ n_features_expected=len(request.app.state.artefacts.feature_names),
106
+ metrics=info.get("metrics", {}),
107
+ )
108
+
109
+
110
+ @app.post("/predict", response_model=PredictionResponse, tags=["scoring"])
111
+ async def predict(payload: PredictionRequest, request: Request) -> PredictionResponse:
112
+ raw_inputs = payload.model_dump()
113
+ sk_id = raw_inputs.pop("SK_ID_CURR")
114
+
115
+ artefacts = request.app.state.artefacts
116
+ predictor: CreditScoringPredictor = request.app.state.predictor
117
+
118
+ try:
119
+ features, client_known = assemble(raw_inputs, sk_id_curr=sk_id, artefacts=artefacts)
120
+ except Exception as exc:
121
+ logger.exception("Failed to assemble features for sk_id=%s", sk_id)
122
+ raise HTTPException(
123
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
124
+ detail=f"Feature assembly failed: {exc.__class__.__name__}",
125
+ ) from exc
126
+
127
+ proba, decision = predictor.predict(features)
128
+
129
+ return PredictionResponse(
130
+ sk_id_curr=sk_id,
131
+ probability_default=proba,
132
+ decision=decision,
133
+ threshold=predictor.threshold,
134
+ model_version=predictor.model_version,
135
+ client_known=client_known,
136
+ )
api/predictor.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Model loading and prediction wrapper.
2
+
3
+ Loaded once at API startup (see api.main:lifespan) — never per-request.
4
+ Wraps the joblib MLflow PyFuncModel so callers don't have to know about the
5
+ internal layout. Threshold is read from model_info.json with a fallback to
6
+ the value in api.settings.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ from pathlib import Path
13
+ from typing import Literal
14
+
15
+ import joblib
16
+ import numpy as np
17
+ import pandas as pd
18
+
19
+ Decision = Literal["GRANTED", "REFUSED"]
20
+
21
+
22
+ class CreditScoringPredictor:
23
+ """Singleton-style wrapper. Build once via load(), reuse for every request."""
24
+
25
+ def __init__(self, model, threshold: float, model_version: str) -> None:
26
+ self._model = model
27
+ self._threshold = threshold
28
+ self._model_version = model_version
29
+
30
+ @classmethod
31
+ def load(
32
+ cls,
33
+ model_path: Path,
34
+ model_info_path: Path,
35
+ default_threshold: float,
36
+ ) -> "CreditScoringPredictor":
37
+ model = joblib.load(model_path)
38
+
39
+ info = json.loads(model_info_path.read_text())
40
+ metrics = info.get("metrics", {})
41
+ threshold = float(metrics.get("best_threshold_mean", default_threshold))
42
+ version = str(info.get("version", "unknown"))
43
+
44
+ return cls(model=model, threshold=threshold, model_version=version)
45
+
46
+ @property
47
+ def threshold(self) -> float:
48
+ return self._threshold
49
+
50
+ @property
51
+ def model_version(self) -> str:
52
+ return self._model_version
53
+
54
+ def predict(self, features: pd.DataFrame) -> tuple[float, Decision]:
55
+ """Return (probability_of_default, decision)."""
56
+ proba = self._predict_proba(features)
57
+ decision: Decision = "REFUSED" if proba >= self._threshold else "GRANTED"
58
+ return proba, decision
59
+
60
+ def _predict_proba(self, features: pd.DataFrame) -> float:
61
+ """Extract the positive-class probability from the underlying model."""
62
+ raw = self._model.predict(features)
63
+
64
+ # MLflow PyFunc models return arrays; sklearn classifiers return 2D probs.
65
+ arr = np.asarray(raw)
66
+ if arr.ndim == 2 and arr.shape[1] == 2:
67
+ return float(arr[0, 1])
68
+ if arr.ndim == 1:
69
+ return float(arr[0])
70
+ raise ValueError(
71
+ f"Unexpected prediction shape {arr.shape}; expected (n,) or (n, 2)."
72
+ )
api/ratios.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Derived ratios computed from raw application_train inputs.
2
+
3
+ Mirrors the 5 ratio features added in feature_engineering/orchestrator.py
4
+ :: app_train_clean(). Re-applied at inference time after JSON inputs override
5
+ the stored row, so the ratios always reflect the user-provided values.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import numpy as np
11
+ import pandas as pd
12
+
13
+
14
+ def apply_derived_ratios(df: pd.DataFrame) -> pd.DataFrame:
15
+ """Compute the 5 ratio features in-place and return the DataFrame.
16
+
17
+ Division by zero or NaN propagates as NaN — LightGBM handles it natively
18
+ using the same routing it learned during training.
19
+ """
20
+ out = df.copy()
21
+
22
+ with np.errstate(divide="ignore", invalid="ignore"):
23
+ out["DAYS_EMPLOYED_PERC"] = _safe_divide(out["DAYS_EMPLOYED"], out["DAYS_BIRTH"])
24
+ out["INCOME_CREDIT_PERC"] = _safe_divide(
25
+ out["AMT_INCOME_TOTAL"], out["AMT_CREDIT"]
26
+ )
27
+ out["INCOME_PER_PERSON"] = _safe_divide(
28
+ out["AMT_INCOME_TOTAL"], out["CNT_FAM_MEMBERS"]
29
+ )
30
+ out["ANNUITY_INCOME_PERC"] = _safe_divide(
31
+ out["AMT_ANNUITY"], out["AMT_INCOME_TOTAL"]
32
+ )
33
+ out["PAYMENT_RATE"] = _safe_divide(out["AMT_ANNUITY"], out["AMT_CREDIT"])
34
+
35
+ return out
36
+
37
+
38
+ def _safe_divide(num: pd.Series, denom: pd.Series) -> pd.Series:
39
+ """Element-wise division returning NaN when denominator is 0 or NaN."""
40
+ result = num / denom
41
+ return result.replace([np.inf, -np.inf], np.nan)
api/schemas.py ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pydantic schemas for the credit scoring API.
2
+
3
+ PredictionRequest exposes every raw application_train column the model was
4
+ trained on (excluding the TARGET label). Drift monitoring needs the full
5
+ input space — so we collect all 120 features + SK_ID_CURR rather than a
6
+ top-N subset.
7
+
8
+ Field ranges are business-driven (e.g. DAYS_BIRTH ∈ [-25550, -6570] = ages
9
+ 18 to 70) rather than blindly fitted on training mins/maxes — this catches
10
+ nonsensical inputs at the API boundary.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from typing import Literal, Optional
16
+
17
+ from pydantic import BaseModel, ConfigDict, Field
18
+
19
+ # ---------------------------------------------------------------------------
20
+ # Categorical literals — exhaustive list captured at training time.
21
+ # Mirrors models/app_train_categories.json. If the categorical vocabulary
22
+ # evolves, regenerate the JSON and update these literals.
23
+ # ---------------------------------------------------------------------------
24
+ ContractType = Literal["Cash loans", "Revolving loans"]
25
+ GenderCode = Literal["F", "M"]
26
+ YN = Literal["Y", "N"]
27
+ TypeSuite = Literal[
28
+ "Children",
29
+ "Family",
30
+ "Group of people",
31
+ "Other_A",
32
+ "Other_B",
33
+ "Spouse, partner",
34
+ "Unaccompanied",
35
+ ]
36
+ IncomeType = Literal[
37
+ "Businessman",
38
+ "Commercial associate",
39
+ "Maternity leave",
40
+ "Pensioner",
41
+ "State servant",
42
+ "Student",
43
+ "Unemployed",
44
+ "Working",
45
+ ]
46
+ EducationType = Literal[
47
+ "Academic degree",
48
+ "Higher education",
49
+ "Incomplete higher",
50
+ "Lower secondary",
51
+ "Secondary / secondary special",
52
+ ]
53
+ FamilyStatus = Literal[
54
+ "Civil marriage",
55
+ "Married",
56
+ "Separated",
57
+ "Single / not married",
58
+ "Unknown",
59
+ "Widow",
60
+ ]
61
+ HousingType = Literal[
62
+ "Co-op apartment",
63
+ "House / apartment",
64
+ "Municipal apartment",
65
+ "Office apartment",
66
+ "Rented apartment",
67
+ "With parents",
68
+ ]
69
+ OccupationType = Literal[
70
+ "Accountants",
71
+ "Cleaning staff",
72
+ "Cooking staff",
73
+ "Core staff",
74
+ "Drivers",
75
+ "HR staff",
76
+ "High skill tech staff",
77
+ "IT staff",
78
+ "Laborers",
79
+ "Low-skill Laborers",
80
+ "Managers",
81
+ "Medicine staff",
82
+ "Private service staff",
83
+ "Realty agents",
84
+ "Sales staff",
85
+ "Secretaries",
86
+ "Security staff",
87
+ "Waiters/barmen staff",
88
+ ]
89
+ WeekDay = Literal[
90
+ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"
91
+ ]
92
+ OrganizationType = Literal[
93
+ "Advertising",
94
+ "Agriculture",
95
+ "Bank",
96
+ "Business Entity Type 1",
97
+ "Business Entity Type 2",
98
+ "Business Entity Type 3",
99
+ "Cleaning",
100
+ "Construction",
101
+ "Culture",
102
+ "Electricity",
103
+ "Emergency",
104
+ "Government",
105
+ "Hotel",
106
+ "Housing",
107
+ "Industry: type 1",
108
+ "Industry: type 10",
109
+ "Industry: type 11",
110
+ "Industry: type 12",
111
+ "Industry: type 13",
112
+ "Industry: type 2",
113
+ "Industry: type 3",
114
+ "Industry: type 4",
115
+ "Industry: type 5",
116
+ "Industry: type 6",
117
+ "Industry: type 7",
118
+ "Industry: type 8",
119
+ "Industry: type 9",
120
+ "Insurance",
121
+ "Kindergarten",
122
+ "Legal Services",
123
+ "Medicine",
124
+ "Military",
125
+ "Mobile",
126
+ "Other",
127
+ "Police",
128
+ "Postal",
129
+ "Realtor",
130
+ "Religion",
131
+ "Restaurant",
132
+ "School",
133
+ "Security",
134
+ "Security Ministries",
135
+ "Self-employed",
136
+ "Services",
137
+ "Telecom",
138
+ "Trade: type 1",
139
+ "Trade: type 2",
140
+ "Trade: type 3",
141
+ "Trade: type 4",
142
+ "Trade: type 5",
143
+ "Trade: type 6",
144
+ "Trade: type 7",
145
+ "Transport: type 1",
146
+ "Transport: type 2",
147
+ "Transport: type 3",
148
+ "Transport: type 4",
149
+ "University",
150
+ "XNA",
151
+ ]
152
+ FondKapremontMode = Literal[
153
+ "not specified", "org spec account", "reg oper account", "reg oper spec account"
154
+ ]
155
+ HouseTypeMode = Literal["block of flats", "specific housing", "terraced house"]
156
+ WallsMaterialMode = Literal[
157
+ "Block", "Mixed", "Monolithic", "Others", "Panel", "Stone, brick", "Wooden"
158
+ ]
159
+ EmergencyStateMode = Literal["No", "Yes"]
160
+
161
+
162
+ # ---------------------------------------------------------------------------
163
+ # Request payload
164
+ # ---------------------------------------------------------------------------
165
+ class PredictionRequest(BaseModel):
166
+ """Raw application_train inputs for one client."""
167
+
168
+ model_config = ConfigDict(extra="forbid")
169
+
170
+ # Identity ---------------------------------------------------------------
171
+ SK_ID_CURR: int = Field(ge=100_000, le=999_999_999, description="Client id")
172
+
173
+ # Contract & demographics ------------------------------------------------
174
+ NAME_CONTRACT_TYPE: ContractType
175
+ CODE_GENDER: GenderCode
176
+ FLAG_OWN_CAR: YN
177
+ FLAG_OWN_REALTY: YN
178
+ CNT_CHILDREN: int = Field(ge=0, le=20)
179
+ AMT_INCOME_TOTAL: float = Field(gt=0)
180
+ AMT_CREDIT: float = Field(gt=0)
181
+ AMT_ANNUITY: Optional[float] = Field(default=None, gt=0)
182
+ AMT_GOODS_PRICE: Optional[float] = Field(default=None, gt=0)
183
+ NAME_TYPE_SUITE: Optional[TypeSuite] = None
184
+ NAME_INCOME_TYPE: IncomeType
185
+ NAME_EDUCATION_TYPE: EducationType
186
+ NAME_FAMILY_STATUS: FamilyStatus
187
+ NAME_HOUSING_TYPE: HousingType
188
+ REGION_POPULATION_RELATIVE: float = Field(ge=0, le=1)
189
+ DAYS_BIRTH: int = Field(le=-6570, ge=-25550, description="Negative days from now")
190
+ DAYS_EMPLOYED: int = Field(
191
+ ge=-25000,
192
+ le=365_243,
193
+ description="Negative days; 365243 sentinel = not employed",
194
+ )
195
+ DAYS_REGISTRATION: float = Field(le=0, ge=-25000)
196
+ DAYS_ID_PUBLISH: int = Field(le=0, ge=-10000)
197
+ OWN_CAR_AGE: Optional[float] = Field(default=None, ge=0, le=100)
198
+ FLAG_MOBIL: int = Field(ge=0, le=1)
199
+ FLAG_EMP_PHONE: int = Field(ge=0, le=1)
200
+ FLAG_WORK_PHONE: int = Field(ge=0, le=1)
201
+ FLAG_CONT_MOBILE: int = Field(ge=0, le=1)
202
+ FLAG_PHONE: int = Field(ge=0, le=1)
203
+ FLAG_EMAIL: int = Field(ge=0, le=1)
204
+ OCCUPATION_TYPE: Optional[OccupationType] = None
205
+ CNT_FAM_MEMBERS: float = Field(ge=1, le=20)
206
+ REGION_RATING_CLIENT: int = Field(ge=1, le=3)
207
+ REGION_RATING_CLIENT_W_CITY: int = Field(ge=1, le=3)
208
+ WEEKDAY_APPR_PROCESS_START: WeekDay
209
+ HOUR_APPR_PROCESS_START: int = Field(ge=0, le=23)
210
+ REG_REGION_NOT_LIVE_REGION: int = Field(ge=0, le=1)
211
+ REG_REGION_NOT_WORK_REGION: int = Field(ge=0, le=1)
212
+ LIVE_REGION_NOT_WORK_REGION: int = Field(ge=0, le=1)
213
+ REG_CITY_NOT_LIVE_CITY: int = Field(ge=0, le=1)
214
+ REG_CITY_NOT_WORK_CITY: int = Field(ge=0, le=1)
215
+ LIVE_CITY_NOT_WORK_CITY: int = Field(ge=0, le=1)
216
+ ORGANIZATION_TYPE: OrganizationType
217
+
218
+ # External scoring sources ----------------------------------------------
219
+ EXT_SOURCE_1: Optional[float] = Field(default=None, ge=0, le=1)
220
+ EXT_SOURCE_2: Optional[float] = Field(default=None, ge=0, le=1)
221
+ EXT_SOURCE_3: Optional[float] = Field(default=None, ge=0, le=1)
222
+
223
+ # Building characteristics (mostly nullable, ratios in [0, 1]) ----------
224
+ APARTMENTS_AVG: Optional[float] = Field(default=None, ge=0, le=1)
225
+ BASEMENTAREA_AVG: Optional[float] = Field(default=None, ge=0, le=1)
226
+ YEARS_BEGINEXPLUATATION_AVG: Optional[float] = Field(default=None, ge=0, le=1)
227
+ YEARS_BUILD_AVG: Optional[float] = Field(default=None, ge=0, le=1)
228
+ COMMONAREA_AVG: Optional[float] = Field(default=None, ge=0, le=1)
229
+ ELEVATORS_AVG: Optional[float] = Field(default=None, ge=0, le=1)
230
+ ENTRANCES_AVG: Optional[float] = Field(default=None, ge=0, le=1)
231
+ FLOORSMAX_AVG: Optional[float] = Field(default=None, ge=0, le=1)
232
+ FLOORSMIN_AVG: Optional[float] = Field(default=None, ge=0, le=1)
233
+ LANDAREA_AVG: Optional[float] = Field(default=None, ge=0, le=1)
234
+ LIVINGAPARTMENTS_AVG: Optional[float] = Field(default=None, ge=0, le=1)
235
+ LIVINGAREA_AVG: Optional[float] = Field(default=None, ge=0, le=1)
236
+ NONLIVINGAPARTMENTS_AVG: Optional[float] = Field(default=None, ge=0, le=1)
237
+ NONLIVINGAREA_AVG: Optional[float] = Field(default=None, ge=0, le=1)
238
+ APARTMENTS_MODE: Optional[float] = Field(default=None, ge=0, le=1)
239
+ BASEMENTAREA_MODE: Optional[float] = Field(default=None, ge=0, le=1)
240
+ YEARS_BEGINEXPLUATATION_MODE: Optional[float] = Field(default=None, ge=0, le=1)
241
+ YEARS_BUILD_MODE: Optional[float] = Field(default=None, ge=0, le=1)
242
+ COMMONAREA_MODE: Optional[float] = Field(default=None, ge=0, le=1)
243
+ ELEVATORS_MODE: Optional[float] = Field(default=None, ge=0, le=1)
244
+ ENTRANCES_MODE: Optional[float] = Field(default=None, ge=0, le=1)
245
+ FLOORSMAX_MODE: Optional[float] = Field(default=None, ge=0, le=1)
246
+ FLOORSMIN_MODE: Optional[float] = Field(default=None, ge=0, le=1)
247
+ LANDAREA_MODE: Optional[float] = Field(default=None, ge=0, le=1)
248
+ LIVINGAPARTMENTS_MODE: Optional[float] = Field(default=None, ge=0, le=1)
249
+ LIVINGAREA_MODE: Optional[float] = Field(default=None, ge=0, le=1)
250
+ NONLIVINGAPARTMENTS_MODE: Optional[float] = Field(default=None, ge=0, le=1)
251
+ NONLIVINGAREA_MODE: Optional[float] = Field(default=None, ge=0, le=1)
252
+ APARTMENTS_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
253
+ BASEMENTAREA_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
254
+ YEARS_BEGINEXPLUATATION_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
255
+ YEARS_BUILD_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
256
+ COMMONAREA_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
257
+ ELEVATORS_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
258
+ ENTRANCES_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
259
+ FLOORSMAX_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
260
+ FLOORSMIN_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
261
+ LANDAREA_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
262
+ LIVINGAPARTMENTS_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
263
+ LIVINGAREA_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
264
+ NONLIVINGAPARTMENTS_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
265
+ NONLIVINGAREA_MEDI: Optional[float] = Field(default=None, ge=0, le=1)
266
+ FONDKAPREMONT_MODE: Optional[FondKapremontMode] = None
267
+ HOUSETYPE_MODE: Optional[HouseTypeMode] = None
268
+ TOTALAREA_MODE: Optional[float] = Field(default=None, ge=0, le=1)
269
+ WALLSMATERIAL_MODE: Optional[WallsMaterialMode] = None
270
+ EMERGENCYSTATE_MODE: Optional[EmergencyStateMode] = None
271
+
272
+ # Social circle ---------------------------------------------------------
273
+ OBS_30_CNT_SOCIAL_CIRCLE: Optional[float] = Field(default=None, ge=0, le=500)
274
+ DEF_30_CNT_SOCIAL_CIRCLE: Optional[float] = Field(default=None, ge=0, le=500)
275
+ OBS_60_CNT_SOCIAL_CIRCLE: Optional[float] = Field(default=None, ge=0, le=500)
276
+ DEF_60_CNT_SOCIAL_CIRCLE: Optional[float] = Field(default=None, ge=0, le=500)
277
+
278
+ DAYS_LAST_PHONE_CHANGE: float = Field(le=0, ge=-15000)
279
+
280
+ # Document flags --------------------------------------------------------
281
+ FLAG_DOCUMENT_2: int = Field(ge=0, le=1)
282
+ FLAG_DOCUMENT_3: int = Field(ge=0, le=1)
283
+ FLAG_DOCUMENT_4: int = Field(ge=0, le=1)
284
+ FLAG_DOCUMENT_5: int = Field(ge=0, le=1)
285
+ FLAG_DOCUMENT_6: int = Field(ge=0, le=1)
286
+ FLAG_DOCUMENT_7: int = Field(ge=0, le=1)
287
+ FLAG_DOCUMENT_8: int = Field(ge=0, le=1)
288
+ FLAG_DOCUMENT_9: int = Field(ge=0, le=1)
289
+ FLAG_DOCUMENT_10: int = Field(ge=0, le=1)
290
+ FLAG_DOCUMENT_11: int = Field(ge=0, le=1)
291
+ FLAG_DOCUMENT_12: int = Field(ge=0, le=1)
292
+ FLAG_DOCUMENT_13: int = Field(ge=0, le=1)
293
+ FLAG_DOCUMENT_14: int = Field(ge=0, le=1)
294
+ FLAG_DOCUMENT_15: int = Field(ge=0, le=1)
295
+ FLAG_DOCUMENT_16: int = Field(ge=0, le=1)
296
+ FLAG_DOCUMENT_17: int = Field(ge=0, le=1)
297
+ FLAG_DOCUMENT_18: int = Field(ge=0, le=1)
298
+ FLAG_DOCUMENT_19: int = Field(ge=0, le=1)
299
+ FLAG_DOCUMENT_20: int = Field(ge=0, le=1)
300
+ FLAG_DOCUMENT_21: int = Field(ge=0, le=1)
301
+
302
+ # Credit bureau request volume -----------------------------------------
303
+ AMT_REQ_CREDIT_BUREAU_HOUR: Optional[float] = Field(default=None, ge=0, le=500)
304
+ AMT_REQ_CREDIT_BUREAU_DAY: Optional[float] = Field(default=None, ge=0, le=500)
305
+ AMT_REQ_CREDIT_BUREAU_WEEK: Optional[float] = Field(default=None, ge=0, le=500)
306
+ AMT_REQ_CREDIT_BUREAU_MON: Optional[float] = Field(default=None, ge=0, le=500)
307
+ AMT_REQ_CREDIT_BUREAU_QRT: Optional[float] = Field(default=None, ge=0, le=500)
308
+ AMT_REQ_CREDIT_BUREAU_YEAR: Optional[float] = Field(default=None, ge=0, le=500)
309
+
310
+
311
+ # ---------------------------------------------------------------------------
312
+ # Response payload
313
+ # ---------------------------------------------------------------------------
314
+ Decision = Literal["GRANTED", "REFUSED"]
315
+
316
+
317
+ class PredictionResponse(BaseModel):
318
+ sk_id_curr: int
319
+ probability_default: float = Field(ge=0, le=1)
320
+ decision: Decision
321
+ threshold: float = Field(ge=0, le=1)
322
+ model_version: str
323
+ client_known: bool = Field(
324
+ description="True if SK_ID_CURR found in feature store; False otherwise."
325
+ )
326
+
327
+
328
+ class HealthResponse(BaseModel):
329
+ status: Literal["ok"]
330
+ model_version: str
331
+
332
+
333
+ class ModelInfoResponse(BaseModel):
334
+ model_name: str
335
+ version: str
336
+ threshold: float
337
+ n_features_expected: int
338
+ metrics: dict
api/settings.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """API runtime configuration. Paths and constants resolved at import time."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ from pathlib import Path
7
+
8
+ ROOT = Path(__file__).resolve().parents[1]
9
+
10
+ MODEL_PATH = Path(os.getenv("OC_P8_MODEL_PATH", ROOT / "models" / "model.joblib"))
11
+ MODEL_INFO_PATH = Path(
12
+ os.getenv("OC_P8_MODEL_INFO_PATH", ROOT / "models" / "model_info.json")
13
+ )
14
+ FEATURE_NAMES_PATH = Path(
15
+ os.getenv("OC_P8_FEATURE_NAMES_PATH", ROOT / "models" / "feature_names.json")
16
+ )
17
+ APP_TRAIN_CATEGORIES_PATH = Path(
18
+ os.getenv(
19
+ "OC_P8_APP_TRAIN_CATEGORIES_PATH",
20
+ ROOT / "models" / "app_train_categories.json",
21
+ )
22
+ )
23
+ APP_TRAIN_BINARY_MAPPINGS_PATH = Path(
24
+ os.getenv(
25
+ "OC_P8_APP_TRAIN_BINARY_MAPPINGS_PATH",
26
+ ROOT / "models" / "app_train_binary_mappings.json",
27
+ )
28
+ )
29
+ NO_HISTORY_TEMPLATE_PATH = Path(
30
+ os.getenv("OC_P8_NO_HISTORY_TEMPLATE_PATH", ROOT / "models" / "no_history_template.json")
31
+ )
32
+ FEATURE_STORE_PATH = Path(
33
+ os.getenv("OC_P8_FEATURE_STORE_PATH", ROOT / "data" / "features_store.parquet")
34
+ )
35
+
36
+ # Default fallback if model_info.json does not expose the optimised threshold.
37
+ DEFAULT_THRESHOLD = 0.33
feature_engineering/__init__.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ """Offline feature engineering module.
2
+
3
+ Contains heavy aggregation logic over bureau, previous_application,
4
+ POS_CASH_BALANCE, credit_card_balance, installments_payments. Used only by
5
+ scripts/build_feature_store.py — never imported by the runtime API.
6
+ """
feature_engineering/aggregations.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Heavy aggregation functions extracted from notebooks/EDA.ipynb.
2
+
3
+ Each function reads one auxiliary CSV (bureau, previous_application,
4
+ POS_CASH_balance, installments_payments, credit_card_balance) and returns
5
+ a DataFrame indexed by SK_ID_CURR with one row per client.
6
+
7
+ These functions are used only offline by scripts/build_feature_store.py.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import gc
13
+ from pathlib import Path
14
+
15
+ import numpy as np
16
+ import pandas as pd
17
+
18
+
19
+ def one_hot_encoder(
20
+ df: pd.DataFrame, nan_as_category: bool = True
21
+ ) -> tuple[pd.DataFrame, list[str]]:
22
+ """One-hot encode all object dtype columns. Returns the encoded df and the
23
+ list of newly created column names."""
24
+ original_columns = list(df.columns)
25
+ categorical_columns = [col for col in df.columns if df[col].dtype == "object"]
26
+ df = pd.get_dummies(df, columns=categorical_columns, dummy_na=nan_as_category)
27
+ new_columns = [c for c in df.columns if c not in original_columns]
28
+ return df, new_columns
29
+
30
+
31
+ def bureau_and_balance(
32
+ data_dir: Path, num_rows: int | None = None, nan_as_category: bool = True
33
+ ) -> pd.DataFrame:
34
+ """Aggregate bureau.csv and bureau_balance.csv per SK_ID_CURR.
35
+
36
+ Produces BURO_*, ACTIVE_*, CLOSED_* columns.
37
+ """
38
+ bureau = pd.read_csv(data_dir / "bureau.csv", nrows=num_rows)
39
+ bb = pd.read_csv(data_dir / "bureau_balance.csv", nrows=num_rows)
40
+ bb, bb_cat = one_hot_encoder(bb, nan_as_category)
41
+ bureau, bureau_cat = one_hot_encoder(bureau, nan_as_category)
42
+
43
+ bb_aggregations: dict[str, list[str]] = {"MONTHS_BALANCE": ["min", "max", "size"]}
44
+ for col in bb_cat:
45
+ bb_aggregations[col] = ["mean"]
46
+ bb_agg = bb.groupby("SK_ID_BUREAU").agg(bb_aggregations)
47
+ bb_agg.columns = pd.Index(
48
+ [e[0] + "_" + e[1].upper() for e in bb_agg.columns.tolist()]
49
+ )
50
+ bureau = bureau.join(bb_agg, how="left", on="SK_ID_BUREAU")
51
+ bureau.drop(["SK_ID_BUREAU"], axis=1, inplace=True)
52
+ del bb, bb_agg
53
+ gc.collect()
54
+
55
+ num_aggregations = {
56
+ "DAYS_CREDIT": ["min", "max", "mean", "var"],
57
+ "DAYS_CREDIT_ENDDATE": ["min", "max", "mean"],
58
+ "DAYS_CREDIT_UPDATE": ["mean"],
59
+ "CREDIT_DAY_OVERDUE": ["max", "mean"],
60
+ "AMT_CREDIT_MAX_OVERDUE": ["mean"],
61
+ "AMT_CREDIT_SUM": ["max", "mean", "sum"],
62
+ "AMT_CREDIT_SUM_DEBT": ["max", "mean", "sum"],
63
+ "AMT_CREDIT_SUM_OVERDUE": ["mean"],
64
+ "AMT_CREDIT_SUM_LIMIT": ["mean", "sum"],
65
+ "AMT_ANNUITY": ["max", "mean"],
66
+ "CNT_CREDIT_PROLONG": ["sum"],
67
+ "MONTHS_BALANCE_MIN": ["min"],
68
+ "MONTHS_BALANCE_MAX": ["max"],
69
+ "MONTHS_BALANCE_SIZE": ["mean", "sum"],
70
+ }
71
+ cat_aggregations: dict[str, list[str]] = {}
72
+ for cat in bureau_cat:
73
+ cat_aggregations[cat] = ["mean"]
74
+ for cat in bb_cat:
75
+ cat_aggregations[cat + "_MEAN"] = ["mean"]
76
+
77
+ bureau_agg = bureau.groupby("SK_ID_CURR").agg(
78
+ {**num_aggregations, **cat_aggregations}
79
+ )
80
+ bureau_agg.columns = pd.Index(
81
+ ["BURO_" + e[0] + "_" + e[1].upper() for e in bureau_agg.columns.tolist()]
82
+ )
83
+
84
+ active = bureau[bureau["CREDIT_ACTIVE_Active"] == 1]
85
+ active_agg = active.groupby("SK_ID_CURR").agg(num_aggregations)
86
+ active_agg.columns = pd.Index(
87
+ ["ACTIVE_" + e[0] + "_" + e[1].upper() for e in active_agg.columns.tolist()]
88
+ )
89
+ bureau_agg = bureau_agg.join(active_agg, how="left", on="SK_ID_CURR")
90
+ del active, active_agg
91
+ gc.collect()
92
+
93
+ closed = bureau[bureau["CREDIT_ACTIVE_Closed"] == 1]
94
+ closed_agg = closed.groupby("SK_ID_CURR").agg(num_aggregations)
95
+ closed_agg.columns = pd.Index(
96
+ ["CLOSED_" + e[0] + "_" + e[1].upper() for e in closed_agg.columns.tolist()]
97
+ )
98
+ bureau_agg = bureau_agg.join(closed_agg, how="left", on="SK_ID_CURR")
99
+ del closed, closed_agg, bureau
100
+ gc.collect()
101
+
102
+ return bureau_agg
103
+
104
+
105
+ def previous_applications(
106
+ data_dir: Path, num_rows: int | None = None, nan_as_category: bool = True
107
+ ) -> pd.DataFrame:
108
+ """Aggregate previous_application.csv per SK_ID_CURR.
109
+
110
+ Produces PREV_*, APPROVED_*, REFUSED_* columns.
111
+ """
112
+ prev = pd.read_csv(data_dir / "previous_application.csv", nrows=num_rows)
113
+ prev, cat_cols = one_hot_encoder(prev, nan_as_category=nan_as_category)
114
+
115
+ for col in [
116
+ "DAYS_FIRST_DRAWING",
117
+ "DAYS_FIRST_DUE",
118
+ "DAYS_LAST_DUE_1ST_VERSION",
119
+ "DAYS_LAST_DUE",
120
+ "DAYS_TERMINATION",
121
+ ]:
122
+ prev[col] = prev[col].replace(365243, np.nan)
123
+
124
+ prev["APP_CREDIT_PERC"] = prev["AMT_APPLICATION"] / prev["AMT_CREDIT"]
125
+
126
+ num_aggregations = {
127
+ "AMT_ANNUITY": ["min", "max", "mean"],
128
+ "AMT_APPLICATION": ["min", "max", "mean"],
129
+ "AMT_CREDIT": ["min", "max", "mean"],
130
+ "APP_CREDIT_PERC": ["min", "max", "mean", "var"],
131
+ "AMT_DOWN_PAYMENT": ["min", "max", "mean"],
132
+ "AMT_GOODS_PRICE": ["min", "max", "mean"],
133
+ "HOUR_APPR_PROCESS_START": ["min", "max", "mean"],
134
+ "RATE_DOWN_PAYMENT": ["min", "max", "mean"],
135
+ "DAYS_DECISION": ["min", "max", "mean"],
136
+ "CNT_PAYMENT": ["mean", "sum"],
137
+ }
138
+ cat_aggregations = {cat: ["mean"] for cat in cat_cols}
139
+
140
+ prev_agg = prev.groupby("SK_ID_CURR").agg({**num_aggregations, **cat_aggregations})
141
+ prev_agg.columns = pd.Index(
142
+ ["PREV_" + e[0] + "_" + e[1].upper() for e in prev_agg.columns.tolist()]
143
+ )
144
+
145
+ approved = prev[prev["NAME_CONTRACT_STATUS_Approved"] == 1]
146
+ approved_agg = approved.groupby("SK_ID_CURR").agg(num_aggregations)
147
+ approved_agg.columns = pd.Index(
148
+ ["APPROVED_" + e[0] + "_" + e[1].upper() for e in approved_agg.columns.tolist()]
149
+ )
150
+ prev_agg = prev_agg.join(approved_agg, how="left", on="SK_ID_CURR")
151
+
152
+ refused = prev[prev["NAME_CONTRACT_STATUS_Refused"] == 1]
153
+ refused_agg = refused.groupby("SK_ID_CURR").agg(num_aggregations)
154
+ refused_agg.columns = pd.Index(
155
+ ["REFUSED_" + e[0] + "_" + e[1].upper() for e in refused_agg.columns.tolist()]
156
+ )
157
+ prev_agg = prev_agg.join(refused_agg, how="left", on="SK_ID_CURR")
158
+ del refused, refused_agg, approved, approved_agg, prev
159
+ gc.collect()
160
+
161
+ return prev_agg
162
+
163
+
164
+ def pos_cash(
165
+ data_dir: Path, num_rows: int | None = None, nan_as_category: bool = True
166
+ ) -> pd.DataFrame:
167
+ """Aggregate POS_CASH_balance.csv per SK_ID_CURR. Produces POS_* columns."""
168
+ pos = pd.read_csv(data_dir / "POS_CASH_balance.csv", nrows=num_rows)
169
+ pos, cat_cols = one_hot_encoder(pos, nan_as_category=nan_as_category)
170
+
171
+ aggregations: dict[str, list[str]] = {
172
+ "MONTHS_BALANCE": ["max", "mean", "size"],
173
+ "SK_DPD": ["max", "mean"],
174
+ "SK_DPD_DEF": ["max", "mean"],
175
+ }
176
+ for cat in cat_cols:
177
+ aggregations[cat] = ["mean"]
178
+
179
+ pos_agg = pos.groupby("SK_ID_CURR").agg(aggregations)
180
+ pos_agg.columns = pd.Index(
181
+ ["POS_" + e[0] + "_" + e[1].upper() for e in pos_agg.columns.tolist()]
182
+ )
183
+ pos_agg["POS_COUNT"] = pos.groupby("SK_ID_CURR").size()
184
+ del pos
185
+ gc.collect()
186
+ return pos_agg
187
+
188
+
189
+ def installments_payments(
190
+ data_dir: Path, num_rows: int | None = None, nan_as_category: bool = True
191
+ ) -> pd.DataFrame:
192
+ """Aggregate installments_payments.csv per SK_ID_CURR. Produces INSTAL_*."""
193
+ ins = pd.read_csv(data_dir / "installments_payments.csv", nrows=num_rows)
194
+ ins, cat_cols = one_hot_encoder(ins, nan_as_category=nan_as_category)
195
+
196
+ ins["PAYMENT_PERC"] = ins["AMT_PAYMENT"] / ins["AMT_INSTALMENT"]
197
+ ins["PAYMENT_DIFF"] = ins["AMT_INSTALMENT"] - ins["AMT_PAYMENT"]
198
+
199
+ ins["DPD"] = ins["DAYS_ENTRY_PAYMENT"] - ins["DAYS_INSTALMENT"]
200
+ ins["DBD"] = ins["DAYS_INSTALMENT"] - ins["DAYS_ENTRY_PAYMENT"]
201
+ ins["DPD"] = ins["DPD"].apply(lambda x: x if x > 0 else 0)
202
+ ins["DBD"] = ins["DBD"].apply(lambda x: x if x > 0 else 0)
203
+
204
+ aggregations: dict[str, list[str]] = {
205
+ "NUM_INSTALMENT_VERSION": ["nunique"],
206
+ "DPD": ["max", "mean", "sum"],
207
+ "DBD": ["max", "mean", "sum"],
208
+ "PAYMENT_PERC": ["max", "mean", "sum", "var"],
209
+ "PAYMENT_DIFF": ["max", "mean", "sum", "var"],
210
+ "AMT_INSTALMENT": ["max", "mean", "sum"],
211
+ "AMT_PAYMENT": ["min", "max", "mean", "sum"],
212
+ "DAYS_ENTRY_PAYMENT": ["max", "mean", "sum"],
213
+ }
214
+ for cat in cat_cols:
215
+ aggregations[cat] = ["mean"]
216
+ ins_agg = ins.groupby("SK_ID_CURR").agg(aggregations)
217
+ ins_agg.columns = pd.Index(
218
+ ["INSTAL_" + e[0] + "_" + e[1].upper() for e in ins_agg.columns.tolist()]
219
+ )
220
+ ins_agg["INSTAL_COUNT"] = ins.groupby("SK_ID_CURR").size()
221
+ del ins
222
+ gc.collect()
223
+ return ins_agg
224
+
225
+
226
+ def credit_card_balance(
227
+ data_dir: Path, num_rows: int | None = None, nan_as_category: bool = True
228
+ ) -> pd.DataFrame:
229
+ """Aggregate credit_card_balance.csv per SK_ID_CURR. Produces CC_* columns."""
230
+ cc = pd.read_csv(data_dir / "credit_card_balance.csv", nrows=num_rows)
231
+ cc, cat_cols = one_hot_encoder(cc, nan_as_category=nan_as_category)
232
+
233
+ cc.drop(["SK_ID_PREV"], axis=1, inplace=True)
234
+
235
+ num_aggregations = {
236
+ col: ["min", "max", "mean", "sum", "var"]
237
+ for col in cc.columns
238
+ if col not in cat_cols
239
+ }
240
+ cat_aggregations = {cat: ["mean"] for cat in cat_cols}
241
+
242
+ cc_agg = cc.groupby("SK_ID_CURR").agg({**num_aggregations, **cat_aggregations})
243
+ cc_agg.columns = pd.Index(
244
+ ["CC_" + e[0] + "_" + e[1].upper() for e in cc_agg.columns.tolist()]
245
+ )
246
+ cc_agg["CC_COUNT"] = cc.groupby("SK_ID_CURR").size()
247
+ del cc
248
+ gc.collect()
249
+ return cc_agg
feature_engineering/orchestrator.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Offline orchestration of the full feature engineering pipeline.
2
+
3
+ Replicates the merge_files() function from notebooks/EDA.ipynb so that the
4
+ parquet feature store can be built once with the same logic that trained
5
+ the model.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import gc
11
+ from pathlib import Path
12
+
13
+ import numpy as np
14
+ import pandas as pd
15
+
16
+ from feature_engineering.aggregations import (
17
+ bureau_and_balance,
18
+ credit_card_balance,
19
+ installments_payments,
20
+ one_hot_encoder,
21
+ pos_cash,
22
+ previous_applications,
23
+ )
24
+
25
+
26
+ def app_train_clean(
27
+ data_dir: Path, num_rows: int | None = None, nan_as_category: bool = False
28
+ ) -> pd.DataFrame:
29
+ """Read application_train.csv and apply the same transformations as the
30
+ training notebook (binary factorize, one-hot, ratio features)."""
31
+ df = pd.read_csv(data_dir / "application_train.csv", nrows=num_rows)
32
+ df = df[df["CODE_GENDER"] != "XNA"]
33
+
34
+ for bin_feature in ["CODE_GENDER", "FLAG_OWN_CAR", "FLAG_OWN_REALTY"]:
35
+ df[bin_feature], _ = pd.factorize(df[bin_feature])
36
+
37
+ df, _ = one_hot_encoder(df, nan_as_category)
38
+
39
+ df["DAYS_EMPLOYED"] = df["DAYS_EMPLOYED"].replace(365243, np.nan)
40
+
41
+ df["DAYS_EMPLOYED_PERC"] = df["DAYS_EMPLOYED"] / df["DAYS_BIRTH"]
42
+ df["INCOME_CREDIT_PERC"] = df["AMT_INCOME_TOTAL"] / df["AMT_CREDIT"]
43
+ df["INCOME_PER_PERSON"] = df["AMT_INCOME_TOTAL"] / df["CNT_FAM_MEMBERS"]
44
+ df["ANNUITY_INCOME_PERC"] = df["AMT_ANNUITY"] / df["AMT_INCOME_TOTAL"]
45
+ df["PAYMENT_RATE"] = df["AMT_ANNUITY"] / df["AMT_CREDIT"]
46
+
47
+ return df
48
+
49
+
50
+ def merge_files(data_dir: Path, debug: bool = False) -> pd.DataFrame:
51
+ """Build the full 770-column training dataframe by joining application_train
52
+ with all auxiliary aggregates. Returns a DataFrame with SK_ID_CURR + TARGET
53
+ + 768 engineered features.
54
+ """
55
+ num_rows = 30000 if debug else None
56
+ df = app_train_clean(data_dir, num_rows)
57
+
58
+ bureau = bureau_and_balance(data_dir, num_rows)
59
+ print("Bureau df shape:", bureau.shape)
60
+ df = df.join(bureau, how="left", on="SK_ID_CURR")
61
+ del bureau
62
+ gc.collect()
63
+
64
+ prev = previous_applications(data_dir, num_rows)
65
+ print("Previous applications df shape:", prev.shape)
66
+ df = df.join(prev, how="left", on="SK_ID_CURR")
67
+ del prev
68
+ gc.collect()
69
+
70
+ pos = pos_cash(data_dir, num_rows)
71
+ print("Pos-cash balance df shape:", pos.shape)
72
+ df = df.join(pos, how="left", on="SK_ID_CURR")
73
+ del pos
74
+ gc.collect()
75
+
76
+ ins = installments_payments(data_dir, num_rows)
77
+ print("Installments payments df shape:", ins.shape)
78
+ df = df.join(ins, how="left", on="SK_ID_CURR")
79
+ del ins
80
+ gc.collect()
81
+
82
+ cc = credit_card_balance(data_dir, num_rows)
83
+ print("Credit card balance df shape:", cc.shape)
84
+ df = df.join(cc, how="left", on="SK_ID_CURR")
85
+ del cc
86
+ gc.collect()
87
+
88
+ return df
models/app_train_binary_mappings.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "CODE_GENDER": {
3
+ "M": 0,
4
+ "F": 1
5
+ },
6
+ "FLAG_OWN_CAR": {
7
+ "N": 0,
8
+ "Y": 1
9
+ },
10
+ "FLAG_OWN_REALTY": {
11
+ "Y": 0,
12
+ "N": 1
13
+ }
14
+ }
models/app_train_categories.json ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "NAME_CONTRACT_TYPE": [
3
+ "Cash loans",
4
+ "Revolving loans"
5
+ ],
6
+ "NAME_TYPE_SUITE": [
7
+ "Children",
8
+ "Family",
9
+ "Group of people",
10
+ "Other_A",
11
+ "Other_B",
12
+ "Spouse, partner",
13
+ "Unaccompanied"
14
+ ],
15
+ "NAME_INCOME_TYPE": [
16
+ "Businessman",
17
+ "Commercial associate",
18
+ "Maternity leave",
19
+ "Pensioner",
20
+ "State servant",
21
+ "Student",
22
+ "Unemployed",
23
+ "Working"
24
+ ],
25
+ "NAME_EDUCATION_TYPE": [
26
+ "Academic degree",
27
+ "Higher education",
28
+ "Incomplete higher",
29
+ "Lower secondary",
30
+ "Secondary / secondary special"
31
+ ],
32
+ "NAME_FAMILY_STATUS": [
33
+ "Civil marriage",
34
+ "Married",
35
+ "Separated",
36
+ "Single / not married",
37
+ "Unknown",
38
+ "Widow"
39
+ ],
40
+ "NAME_HOUSING_TYPE": [
41
+ "Co-op apartment",
42
+ "House / apartment",
43
+ "Municipal apartment",
44
+ "Office apartment",
45
+ "Rented apartment",
46
+ "With parents"
47
+ ],
48
+ "OCCUPATION_TYPE": [
49
+ "Accountants",
50
+ "Cleaning staff",
51
+ "Cooking staff",
52
+ "Core staff",
53
+ "Drivers",
54
+ "HR staff",
55
+ "High skill tech staff",
56
+ "IT staff",
57
+ "Laborers",
58
+ "Low-skill Laborers",
59
+ "Managers",
60
+ "Medicine staff",
61
+ "Private service staff",
62
+ "Realty agents",
63
+ "Sales staff",
64
+ "Secretaries",
65
+ "Security staff",
66
+ "Waiters/barmen staff"
67
+ ],
68
+ "WEEKDAY_APPR_PROCESS_START": [
69
+ "FRIDAY",
70
+ "MONDAY",
71
+ "SATURDAY",
72
+ "SUNDAY",
73
+ "THURSDAY",
74
+ "TUESDAY",
75
+ "WEDNESDAY"
76
+ ],
77
+ "ORGANIZATION_TYPE": [
78
+ "Advertising",
79
+ "Agriculture",
80
+ "Bank",
81
+ "Business Entity Type 1",
82
+ "Business Entity Type 2",
83
+ "Business Entity Type 3",
84
+ "Cleaning",
85
+ "Construction",
86
+ "Culture",
87
+ "Electricity",
88
+ "Emergency",
89
+ "Government",
90
+ "Hotel",
91
+ "Housing",
92
+ "Industry: type 1",
93
+ "Industry: type 10",
94
+ "Industry: type 11",
95
+ "Industry: type 12",
96
+ "Industry: type 13",
97
+ "Industry: type 2",
98
+ "Industry: type 3",
99
+ "Industry: type 4",
100
+ "Industry: type 5",
101
+ "Industry: type 6",
102
+ "Industry: type 7",
103
+ "Industry: type 8",
104
+ "Industry: type 9",
105
+ "Insurance",
106
+ "Kindergarten",
107
+ "Legal Services",
108
+ "Medicine",
109
+ "Military",
110
+ "Mobile",
111
+ "Other",
112
+ "Police",
113
+ "Postal",
114
+ "Realtor",
115
+ "Religion",
116
+ "Restaurant",
117
+ "School",
118
+ "Security",
119
+ "Security Ministries",
120
+ "Self-employed",
121
+ "Services",
122
+ "Telecom",
123
+ "Trade: type 1",
124
+ "Trade: type 2",
125
+ "Trade: type 3",
126
+ "Trade: type 4",
127
+ "Trade: type 5",
128
+ "Trade: type 6",
129
+ "Trade: type 7",
130
+ "Transport: type 1",
131
+ "Transport: type 2",
132
+ "Transport: type 3",
133
+ "Transport: type 4",
134
+ "University",
135
+ "XNA"
136
+ ],
137
+ "FONDKAPREMONT_MODE": [
138
+ "not specified",
139
+ "org spec account",
140
+ "reg oper account",
141
+ "reg oper spec account"
142
+ ],
143
+ "HOUSETYPE_MODE": [
144
+ "block of flats",
145
+ "specific housing",
146
+ "terraced house"
147
+ ],
148
+ "WALLSMATERIAL_MODE": [
149
+ "Block",
150
+ "Mixed",
151
+ "Monolithic",
152
+ "Others",
153
+ "Panel",
154
+ "Stone, brick",
155
+ "Wooden"
156
+ ],
157
+ "EMERGENCYSTATE_MODE": [
158
+ "No",
159
+ "Yes"
160
+ ]
161
+ }
models/app_train_columns.json ADDED
@@ -0,0 +1,979 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "SK_ID_CURR": {
3
+ "dtype": "int64",
4
+ "n_missing": 0,
5
+ "min": 100002.0,
6
+ "max": 456255.0,
7
+ "sample": 100002.0
8
+ },
9
+ "TARGET": {
10
+ "dtype": "int64",
11
+ "n_missing": 0,
12
+ "min": 0.0,
13
+ "max": 1.0,
14
+ "sample": 1.0
15
+ },
16
+ "NAME_CONTRACT_TYPE": {
17
+ "dtype": "object",
18
+ "n_missing": 0,
19
+ "categories": [
20
+ "Cash loans",
21
+ "Revolving loans"
22
+ ]
23
+ },
24
+ "CODE_GENDER": {
25
+ "dtype": "object",
26
+ "n_missing": 0,
27
+ "categories": [
28
+ "F",
29
+ "M"
30
+ ]
31
+ },
32
+ "FLAG_OWN_CAR": {
33
+ "dtype": "object",
34
+ "n_missing": 0,
35
+ "categories": [
36
+ "N",
37
+ "Y"
38
+ ]
39
+ },
40
+ "FLAG_OWN_REALTY": {
41
+ "dtype": "object",
42
+ "n_missing": 0,
43
+ "categories": [
44
+ "N",
45
+ "Y"
46
+ ]
47
+ },
48
+ "CNT_CHILDREN": {
49
+ "dtype": "int64",
50
+ "n_missing": 0,
51
+ "min": 0.0,
52
+ "max": 19.0,
53
+ "sample": 0.0
54
+ },
55
+ "AMT_INCOME_TOTAL": {
56
+ "dtype": "float64",
57
+ "n_missing": 0,
58
+ "min": 25650.0,
59
+ "max": 117000000.0,
60
+ "sample": 202500.0
61
+ },
62
+ "AMT_CREDIT": {
63
+ "dtype": "float64",
64
+ "n_missing": 0,
65
+ "min": 45000.0,
66
+ "max": 4050000.0,
67
+ "sample": 406597.5
68
+ },
69
+ "AMT_ANNUITY": {
70
+ "dtype": "float64",
71
+ "n_missing": 12,
72
+ "min": 1615.5,
73
+ "max": 258025.5,
74
+ "sample": 24700.5
75
+ },
76
+ "AMT_GOODS_PRICE": {
77
+ "dtype": "float64",
78
+ "n_missing": 278,
79
+ "min": 40500.0,
80
+ "max": 4050000.0,
81
+ "sample": 351000.0
82
+ },
83
+ "NAME_TYPE_SUITE": {
84
+ "dtype": "object",
85
+ "n_missing": 1292,
86
+ "categories": [
87
+ "Children",
88
+ "Family",
89
+ "Group of people",
90
+ "Other_A",
91
+ "Other_B",
92
+ "Spouse, partner",
93
+ "Unaccompanied"
94
+ ]
95
+ },
96
+ "NAME_INCOME_TYPE": {
97
+ "dtype": "object",
98
+ "n_missing": 0,
99
+ "categories": [
100
+ "Businessman",
101
+ "Commercial associate",
102
+ "Maternity leave",
103
+ "Pensioner",
104
+ "State servant",
105
+ "Student",
106
+ "Unemployed",
107
+ "Working"
108
+ ]
109
+ },
110
+ "NAME_EDUCATION_TYPE": {
111
+ "dtype": "object",
112
+ "n_missing": 0,
113
+ "categories": [
114
+ "Academic degree",
115
+ "Higher education",
116
+ "Incomplete higher",
117
+ "Lower secondary",
118
+ "Secondary / secondary special"
119
+ ]
120
+ },
121
+ "NAME_FAMILY_STATUS": {
122
+ "dtype": "object",
123
+ "n_missing": 0,
124
+ "categories": [
125
+ "Civil marriage",
126
+ "Married",
127
+ "Separated",
128
+ "Single / not married",
129
+ "Unknown",
130
+ "Widow"
131
+ ]
132
+ },
133
+ "NAME_HOUSING_TYPE": {
134
+ "dtype": "object",
135
+ "n_missing": 0,
136
+ "categories": [
137
+ "Co-op apartment",
138
+ "House / apartment",
139
+ "Municipal apartment",
140
+ "Office apartment",
141
+ "Rented apartment",
142
+ "With parents"
143
+ ]
144
+ },
145
+ "REGION_POPULATION_RELATIVE": {
146
+ "dtype": "float64",
147
+ "n_missing": 0,
148
+ "min": 0.00029,
149
+ "max": 0.072508,
150
+ "sample": 0.018801
151
+ },
152
+ "DAYS_BIRTH": {
153
+ "dtype": "int64",
154
+ "n_missing": 0,
155
+ "min": -25229.0,
156
+ "max": -7489.0,
157
+ "sample": -9461.0
158
+ },
159
+ "DAYS_EMPLOYED": {
160
+ "dtype": "int64",
161
+ "n_missing": 0,
162
+ "min": -17912.0,
163
+ "max": 365243.0,
164
+ "sample": -637.0
165
+ },
166
+ "DAYS_REGISTRATION": {
167
+ "dtype": "float64",
168
+ "n_missing": 0,
169
+ "min": -24672.0,
170
+ "max": 0.0,
171
+ "sample": -3648.0
172
+ },
173
+ "DAYS_ID_PUBLISH": {
174
+ "dtype": "int64",
175
+ "n_missing": 0,
176
+ "min": -7197.0,
177
+ "max": 0.0,
178
+ "sample": -2120.0
179
+ },
180
+ "OWN_CAR_AGE": {
181
+ "dtype": "float64",
182
+ "n_missing": 202927,
183
+ "min": 0.0,
184
+ "max": 91.0,
185
+ "sample": 26.0
186
+ },
187
+ "FLAG_MOBIL": {
188
+ "dtype": "int64",
189
+ "n_missing": 0,
190
+ "min": 0.0,
191
+ "max": 1.0,
192
+ "sample": 1.0
193
+ },
194
+ "FLAG_EMP_PHONE": {
195
+ "dtype": "int64",
196
+ "n_missing": 0,
197
+ "min": 0.0,
198
+ "max": 1.0,
199
+ "sample": 1.0
200
+ },
201
+ "FLAG_WORK_PHONE": {
202
+ "dtype": "int64",
203
+ "n_missing": 0,
204
+ "min": 0.0,
205
+ "max": 1.0,
206
+ "sample": 0.0
207
+ },
208
+ "FLAG_CONT_MOBILE": {
209
+ "dtype": "int64",
210
+ "n_missing": 0,
211
+ "min": 0.0,
212
+ "max": 1.0,
213
+ "sample": 1.0
214
+ },
215
+ "FLAG_PHONE": {
216
+ "dtype": "int64",
217
+ "n_missing": 0,
218
+ "min": 0.0,
219
+ "max": 1.0,
220
+ "sample": 1.0
221
+ },
222
+ "FLAG_EMAIL": {
223
+ "dtype": "int64",
224
+ "n_missing": 0,
225
+ "min": 0.0,
226
+ "max": 1.0,
227
+ "sample": 0.0
228
+ },
229
+ "OCCUPATION_TYPE": {
230
+ "dtype": "object",
231
+ "n_missing": 96389,
232
+ "categories": [
233
+ "Accountants",
234
+ "Cleaning staff",
235
+ "Cooking staff",
236
+ "Core staff",
237
+ "Drivers",
238
+ "HR staff",
239
+ "High skill tech staff",
240
+ "IT staff",
241
+ "Laborers",
242
+ "Low-skill Laborers",
243
+ "Managers",
244
+ "Medicine staff",
245
+ "Private service staff",
246
+ "Realty agents",
247
+ "Sales staff",
248
+ "Secretaries",
249
+ "Security staff",
250
+ "Waiters/barmen staff"
251
+ ]
252
+ },
253
+ "CNT_FAM_MEMBERS": {
254
+ "dtype": "float64",
255
+ "n_missing": 2,
256
+ "min": 1.0,
257
+ "max": 20.0,
258
+ "sample": 1.0
259
+ },
260
+ "REGION_RATING_CLIENT": {
261
+ "dtype": "int64",
262
+ "n_missing": 0,
263
+ "min": 1.0,
264
+ "max": 3.0,
265
+ "sample": 2.0
266
+ },
267
+ "REGION_RATING_CLIENT_W_CITY": {
268
+ "dtype": "int64",
269
+ "n_missing": 0,
270
+ "min": 1.0,
271
+ "max": 3.0,
272
+ "sample": 2.0
273
+ },
274
+ "WEEKDAY_APPR_PROCESS_START": {
275
+ "dtype": "object",
276
+ "n_missing": 0,
277
+ "categories": [
278
+ "FRIDAY",
279
+ "MONDAY",
280
+ "SATURDAY",
281
+ "SUNDAY",
282
+ "THURSDAY",
283
+ "TUESDAY",
284
+ "WEDNESDAY"
285
+ ]
286
+ },
287
+ "HOUR_APPR_PROCESS_START": {
288
+ "dtype": "int64",
289
+ "n_missing": 0,
290
+ "min": 0.0,
291
+ "max": 23.0,
292
+ "sample": 10.0
293
+ },
294
+ "REG_REGION_NOT_LIVE_REGION": {
295
+ "dtype": "int64",
296
+ "n_missing": 0,
297
+ "min": 0.0,
298
+ "max": 1.0,
299
+ "sample": 0.0
300
+ },
301
+ "REG_REGION_NOT_WORK_REGION": {
302
+ "dtype": "int64",
303
+ "n_missing": 0,
304
+ "min": 0.0,
305
+ "max": 1.0,
306
+ "sample": 0.0
307
+ },
308
+ "LIVE_REGION_NOT_WORK_REGION": {
309
+ "dtype": "int64",
310
+ "n_missing": 0,
311
+ "min": 0.0,
312
+ "max": 1.0,
313
+ "sample": 0.0
314
+ },
315
+ "REG_CITY_NOT_LIVE_CITY": {
316
+ "dtype": "int64",
317
+ "n_missing": 0,
318
+ "min": 0.0,
319
+ "max": 1.0,
320
+ "sample": 0.0
321
+ },
322
+ "REG_CITY_NOT_WORK_CITY": {
323
+ "dtype": "int64",
324
+ "n_missing": 0,
325
+ "min": 0.0,
326
+ "max": 1.0,
327
+ "sample": 0.0
328
+ },
329
+ "LIVE_CITY_NOT_WORK_CITY": {
330
+ "dtype": "int64",
331
+ "n_missing": 0,
332
+ "min": 0.0,
333
+ "max": 1.0,
334
+ "sample": 0.0
335
+ },
336
+ "ORGANIZATION_TYPE": {
337
+ "dtype": "object",
338
+ "n_missing": 0,
339
+ "categories": [
340
+ "Advertising",
341
+ "Agriculture",
342
+ "Bank",
343
+ "Business Entity Type 1",
344
+ "Business Entity Type 2",
345
+ "Business Entity Type 3",
346
+ "Cleaning",
347
+ "Construction",
348
+ "Culture",
349
+ "Electricity",
350
+ "Emergency",
351
+ "Government",
352
+ "Hotel",
353
+ "Housing",
354
+ "Industry: type 1",
355
+ "Industry: type 10",
356
+ "Industry: type 11",
357
+ "Industry: type 12",
358
+ "Industry: type 13",
359
+ "Industry: type 2",
360
+ "Industry: type 3",
361
+ "Industry: type 4",
362
+ "Industry: type 5",
363
+ "Industry: type 6",
364
+ "Industry: type 7",
365
+ "Industry: type 8",
366
+ "Industry: type 9",
367
+ "Insurance",
368
+ "Kindergarten",
369
+ "Legal Services",
370
+ "Medicine",
371
+ "Military",
372
+ "Mobile",
373
+ "Other",
374
+ "Police",
375
+ "Postal",
376
+ "Realtor",
377
+ "Religion",
378
+ "Restaurant",
379
+ "School",
380
+ "Security",
381
+ "Security Ministries",
382
+ "Self-employed",
383
+ "Services",
384
+ "Telecom",
385
+ "Trade: type 1",
386
+ "Trade: type 2",
387
+ "Trade: type 3",
388
+ "Trade: type 4",
389
+ "Trade: type 5",
390
+ "Trade: type 6",
391
+ "Trade: type 7",
392
+ "Transport: type 1",
393
+ "Transport: type 2",
394
+ "Transport: type 3",
395
+ "Transport: type 4",
396
+ "University",
397
+ "XNA"
398
+ ]
399
+ },
400
+ "EXT_SOURCE_1": {
401
+ "dtype": "float64",
402
+ "n_missing": 173376,
403
+ "min": 0.0145681324124455,
404
+ "max": 0.962692770561306,
405
+ "sample": 0.0830369673913225
406
+ },
407
+ "EXT_SOURCE_2": {
408
+ "dtype": "float64",
409
+ "n_missing": 660,
410
+ "min": 8.173616518884397e-08,
411
+ "max": 0.8549996664047012,
412
+ "sample": 0.2629485927471776
413
+ },
414
+ "EXT_SOURCE_3": {
415
+ "dtype": "float64",
416
+ "n_missing": 60965,
417
+ "min": 0.0005272652387098,
418
+ "max": 0.8960095494948396,
419
+ "sample": 0.1393757800997895
420
+ },
421
+ "APARTMENTS_AVG": {
422
+ "dtype": "float64",
423
+ "n_missing": 156060,
424
+ "min": 0.0,
425
+ "max": 1.0,
426
+ "sample": 0.0247
427
+ },
428
+ "BASEMENTAREA_AVG": {
429
+ "dtype": "float64",
430
+ "n_missing": 179942,
431
+ "min": 0.0,
432
+ "max": 1.0,
433
+ "sample": 0.0369
434
+ },
435
+ "YEARS_BEGINEXPLUATATION_AVG": {
436
+ "dtype": "float64",
437
+ "n_missing": 150006,
438
+ "min": 0.0,
439
+ "max": 1.0,
440
+ "sample": 0.9722
441
+ },
442
+ "YEARS_BUILD_AVG": {
443
+ "dtype": "float64",
444
+ "n_missing": 204486,
445
+ "min": 0.0,
446
+ "max": 1.0,
447
+ "sample": 0.6192
448
+ },
449
+ "COMMONAREA_AVG": {
450
+ "dtype": "float64",
451
+ "n_missing": 214862,
452
+ "min": 0.0,
453
+ "max": 1.0,
454
+ "sample": 0.0143
455
+ },
456
+ "ELEVATORS_AVG": {
457
+ "dtype": "float64",
458
+ "n_missing": 163890,
459
+ "min": 0.0,
460
+ "max": 1.0,
461
+ "sample": 0.0
462
+ },
463
+ "ENTRANCES_AVG": {
464
+ "dtype": "float64",
465
+ "n_missing": 154827,
466
+ "min": 0.0,
467
+ "max": 1.0,
468
+ "sample": 0.069
469
+ },
470
+ "FLOORSMAX_AVG": {
471
+ "dtype": "float64",
472
+ "n_missing": 153019,
473
+ "min": 0.0,
474
+ "max": 1.0,
475
+ "sample": 0.0833
476
+ },
477
+ "FLOORSMIN_AVG": {
478
+ "dtype": "float64",
479
+ "n_missing": 208640,
480
+ "min": 0.0,
481
+ "max": 1.0,
482
+ "sample": 0.125
483
+ },
484
+ "LANDAREA_AVG": {
485
+ "dtype": "float64",
486
+ "n_missing": 182588,
487
+ "min": 0.0,
488
+ "max": 1.0,
489
+ "sample": 0.0369
490
+ },
491
+ "LIVINGAPARTMENTS_AVG": {
492
+ "dtype": "float64",
493
+ "n_missing": 210197,
494
+ "min": 0.0,
495
+ "max": 1.0,
496
+ "sample": 0.0202
497
+ },
498
+ "LIVINGAREA_AVG": {
499
+ "dtype": "float64",
500
+ "n_missing": 154349,
501
+ "min": 0.0,
502
+ "max": 1.0,
503
+ "sample": 0.019
504
+ },
505
+ "NONLIVINGAPARTMENTS_AVG": {
506
+ "dtype": "float64",
507
+ "n_missing": 213512,
508
+ "min": 0.0,
509
+ "max": 1.0,
510
+ "sample": 0.0
511
+ },
512
+ "NONLIVINGAREA_AVG": {
513
+ "dtype": "float64",
514
+ "n_missing": 169680,
515
+ "min": 0.0,
516
+ "max": 1.0,
517
+ "sample": 0.0
518
+ },
519
+ "APARTMENTS_MODE": {
520
+ "dtype": "float64",
521
+ "n_missing": 156060,
522
+ "min": 0.0,
523
+ "max": 1.0,
524
+ "sample": 0.0252
525
+ },
526
+ "BASEMENTAREA_MODE": {
527
+ "dtype": "float64",
528
+ "n_missing": 179942,
529
+ "min": 0.0,
530
+ "max": 1.0,
531
+ "sample": 0.0383
532
+ },
533
+ "YEARS_BEGINEXPLUATATION_MODE": {
534
+ "dtype": "float64",
535
+ "n_missing": 150006,
536
+ "min": 0.0,
537
+ "max": 1.0,
538
+ "sample": 0.9722
539
+ },
540
+ "YEARS_BUILD_MODE": {
541
+ "dtype": "float64",
542
+ "n_missing": 204486,
543
+ "min": 0.0,
544
+ "max": 1.0,
545
+ "sample": 0.6341
546
+ },
547
+ "COMMONAREA_MODE": {
548
+ "dtype": "float64",
549
+ "n_missing": 214862,
550
+ "min": 0.0,
551
+ "max": 1.0,
552
+ "sample": 0.0144
553
+ },
554
+ "ELEVATORS_MODE": {
555
+ "dtype": "float64",
556
+ "n_missing": 163890,
557
+ "min": 0.0,
558
+ "max": 1.0,
559
+ "sample": 0.0
560
+ },
561
+ "ENTRANCES_MODE": {
562
+ "dtype": "float64",
563
+ "n_missing": 154827,
564
+ "min": 0.0,
565
+ "max": 1.0,
566
+ "sample": 0.069
567
+ },
568
+ "FLOORSMAX_MODE": {
569
+ "dtype": "float64",
570
+ "n_missing": 153019,
571
+ "min": 0.0,
572
+ "max": 1.0,
573
+ "sample": 0.0833
574
+ },
575
+ "FLOORSMIN_MODE": {
576
+ "dtype": "float64",
577
+ "n_missing": 208640,
578
+ "min": 0.0,
579
+ "max": 1.0,
580
+ "sample": 0.125
581
+ },
582
+ "LANDAREA_MODE": {
583
+ "dtype": "float64",
584
+ "n_missing": 182588,
585
+ "min": 0.0,
586
+ "max": 1.0,
587
+ "sample": 0.0377
588
+ },
589
+ "LIVINGAPARTMENTS_MODE": {
590
+ "dtype": "float64",
591
+ "n_missing": 210197,
592
+ "min": 0.0,
593
+ "max": 1.0,
594
+ "sample": 0.022
595
+ },
596
+ "LIVINGAREA_MODE": {
597
+ "dtype": "float64",
598
+ "n_missing": 154349,
599
+ "min": 0.0,
600
+ "max": 1.0,
601
+ "sample": 0.0198
602
+ },
603
+ "NONLIVINGAPARTMENTS_MODE": {
604
+ "dtype": "float64",
605
+ "n_missing": 213512,
606
+ "min": 0.0,
607
+ "max": 1.0,
608
+ "sample": 0.0
609
+ },
610
+ "NONLIVINGAREA_MODE": {
611
+ "dtype": "float64",
612
+ "n_missing": 169680,
613
+ "min": 0.0,
614
+ "max": 1.0,
615
+ "sample": 0.0
616
+ },
617
+ "APARTMENTS_MEDI": {
618
+ "dtype": "float64",
619
+ "n_missing": 156060,
620
+ "min": 0.0,
621
+ "max": 1.0,
622
+ "sample": 0.025
623
+ },
624
+ "BASEMENTAREA_MEDI": {
625
+ "dtype": "float64",
626
+ "n_missing": 179942,
627
+ "min": 0.0,
628
+ "max": 1.0,
629
+ "sample": 0.0369
630
+ },
631
+ "YEARS_BEGINEXPLUATATION_MEDI": {
632
+ "dtype": "float64",
633
+ "n_missing": 150006,
634
+ "min": 0.0,
635
+ "max": 1.0,
636
+ "sample": 0.9722
637
+ },
638
+ "YEARS_BUILD_MEDI": {
639
+ "dtype": "float64",
640
+ "n_missing": 204486,
641
+ "min": 0.0,
642
+ "max": 1.0,
643
+ "sample": 0.6243
644
+ },
645
+ "COMMONAREA_MEDI": {
646
+ "dtype": "float64",
647
+ "n_missing": 214862,
648
+ "min": 0.0,
649
+ "max": 1.0,
650
+ "sample": 0.0144
651
+ },
652
+ "ELEVATORS_MEDI": {
653
+ "dtype": "float64",
654
+ "n_missing": 163890,
655
+ "min": 0.0,
656
+ "max": 1.0,
657
+ "sample": 0.0
658
+ },
659
+ "ENTRANCES_MEDI": {
660
+ "dtype": "float64",
661
+ "n_missing": 154827,
662
+ "min": 0.0,
663
+ "max": 1.0,
664
+ "sample": 0.069
665
+ },
666
+ "FLOORSMAX_MEDI": {
667
+ "dtype": "float64",
668
+ "n_missing": 153019,
669
+ "min": 0.0,
670
+ "max": 1.0,
671
+ "sample": 0.0833
672
+ },
673
+ "FLOORSMIN_MEDI": {
674
+ "dtype": "float64",
675
+ "n_missing": 208640,
676
+ "min": 0.0,
677
+ "max": 1.0,
678
+ "sample": 0.125
679
+ },
680
+ "LANDAREA_MEDI": {
681
+ "dtype": "float64",
682
+ "n_missing": 182588,
683
+ "min": 0.0,
684
+ "max": 1.0,
685
+ "sample": 0.0375
686
+ },
687
+ "LIVINGAPARTMENTS_MEDI": {
688
+ "dtype": "float64",
689
+ "n_missing": 210197,
690
+ "min": 0.0,
691
+ "max": 1.0,
692
+ "sample": 0.0205
693
+ },
694
+ "LIVINGAREA_MEDI": {
695
+ "dtype": "float64",
696
+ "n_missing": 154349,
697
+ "min": 0.0,
698
+ "max": 1.0,
699
+ "sample": 0.0193
700
+ },
701
+ "NONLIVINGAPARTMENTS_MEDI": {
702
+ "dtype": "float64",
703
+ "n_missing": 213512,
704
+ "min": 0.0,
705
+ "max": 1.0,
706
+ "sample": 0.0
707
+ },
708
+ "NONLIVINGAREA_MEDI": {
709
+ "dtype": "float64",
710
+ "n_missing": 169680,
711
+ "min": 0.0,
712
+ "max": 1.0,
713
+ "sample": 0.0
714
+ },
715
+ "FONDKAPREMONT_MODE": {
716
+ "dtype": "object",
717
+ "n_missing": 210293,
718
+ "categories": [
719
+ "not specified",
720
+ "org spec account",
721
+ "reg oper account",
722
+ "reg oper spec account"
723
+ ]
724
+ },
725
+ "HOUSETYPE_MODE": {
726
+ "dtype": "object",
727
+ "n_missing": 154296,
728
+ "categories": [
729
+ "block of flats",
730
+ "specific housing",
731
+ "terraced house"
732
+ ]
733
+ },
734
+ "TOTALAREA_MODE": {
735
+ "dtype": "float64",
736
+ "n_missing": 148430,
737
+ "min": 0.0,
738
+ "max": 1.0,
739
+ "sample": 0.0149
740
+ },
741
+ "WALLSMATERIAL_MODE": {
742
+ "dtype": "object",
743
+ "n_missing": 156340,
744
+ "categories": [
745
+ "Block",
746
+ "Mixed",
747
+ "Monolithic",
748
+ "Others",
749
+ "Panel",
750
+ "Stone, brick",
751
+ "Wooden"
752
+ ]
753
+ },
754
+ "EMERGENCYSTATE_MODE": {
755
+ "dtype": "object",
756
+ "n_missing": 145754,
757
+ "categories": [
758
+ "No",
759
+ "Yes"
760
+ ]
761
+ },
762
+ "OBS_30_CNT_SOCIAL_CIRCLE": {
763
+ "dtype": "float64",
764
+ "n_missing": 1021,
765
+ "min": 0.0,
766
+ "max": 348.0,
767
+ "sample": 2.0
768
+ },
769
+ "DEF_30_CNT_SOCIAL_CIRCLE": {
770
+ "dtype": "float64",
771
+ "n_missing": 1021,
772
+ "min": 0.0,
773
+ "max": 34.0,
774
+ "sample": 2.0
775
+ },
776
+ "OBS_60_CNT_SOCIAL_CIRCLE": {
777
+ "dtype": "float64",
778
+ "n_missing": 1021,
779
+ "min": 0.0,
780
+ "max": 344.0,
781
+ "sample": 2.0
782
+ },
783
+ "DEF_60_CNT_SOCIAL_CIRCLE": {
784
+ "dtype": "float64",
785
+ "n_missing": 1021,
786
+ "min": 0.0,
787
+ "max": 24.0,
788
+ "sample": 2.0
789
+ },
790
+ "DAYS_LAST_PHONE_CHANGE": {
791
+ "dtype": "float64",
792
+ "n_missing": 1,
793
+ "min": -4292.0,
794
+ "max": 0.0,
795
+ "sample": -1134.0
796
+ },
797
+ "FLAG_DOCUMENT_2": {
798
+ "dtype": "int64",
799
+ "n_missing": 0,
800
+ "min": 0.0,
801
+ "max": 1.0,
802
+ "sample": 0.0
803
+ },
804
+ "FLAG_DOCUMENT_3": {
805
+ "dtype": "int64",
806
+ "n_missing": 0,
807
+ "min": 0.0,
808
+ "max": 1.0,
809
+ "sample": 1.0
810
+ },
811
+ "FLAG_DOCUMENT_4": {
812
+ "dtype": "int64",
813
+ "n_missing": 0,
814
+ "min": 0.0,
815
+ "max": 1.0,
816
+ "sample": 0.0
817
+ },
818
+ "FLAG_DOCUMENT_5": {
819
+ "dtype": "int64",
820
+ "n_missing": 0,
821
+ "min": 0.0,
822
+ "max": 1.0,
823
+ "sample": 0.0
824
+ },
825
+ "FLAG_DOCUMENT_6": {
826
+ "dtype": "int64",
827
+ "n_missing": 0,
828
+ "min": 0.0,
829
+ "max": 1.0,
830
+ "sample": 0.0
831
+ },
832
+ "FLAG_DOCUMENT_7": {
833
+ "dtype": "int64",
834
+ "n_missing": 0,
835
+ "min": 0.0,
836
+ "max": 1.0,
837
+ "sample": 0.0
838
+ },
839
+ "FLAG_DOCUMENT_8": {
840
+ "dtype": "int64",
841
+ "n_missing": 0,
842
+ "min": 0.0,
843
+ "max": 1.0,
844
+ "sample": 0.0
845
+ },
846
+ "FLAG_DOCUMENT_9": {
847
+ "dtype": "int64",
848
+ "n_missing": 0,
849
+ "min": 0.0,
850
+ "max": 1.0,
851
+ "sample": 0.0
852
+ },
853
+ "FLAG_DOCUMENT_10": {
854
+ "dtype": "int64",
855
+ "n_missing": 0,
856
+ "min": 0.0,
857
+ "max": 1.0,
858
+ "sample": 0.0
859
+ },
860
+ "FLAG_DOCUMENT_11": {
861
+ "dtype": "int64",
862
+ "n_missing": 0,
863
+ "min": 0.0,
864
+ "max": 1.0,
865
+ "sample": 0.0
866
+ },
867
+ "FLAG_DOCUMENT_12": {
868
+ "dtype": "int64",
869
+ "n_missing": 0,
870
+ "min": 0.0,
871
+ "max": 1.0,
872
+ "sample": 0.0
873
+ },
874
+ "FLAG_DOCUMENT_13": {
875
+ "dtype": "int64",
876
+ "n_missing": 0,
877
+ "min": 0.0,
878
+ "max": 1.0,
879
+ "sample": 0.0
880
+ },
881
+ "FLAG_DOCUMENT_14": {
882
+ "dtype": "int64",
883
+ "n_missing": 0,
884
+ "min": 0.0,
885
+ "max": 1.0,
886
+ "sample": 0.0
887
+ },
888
+ "FLAG_DOCUMENT_15": {
889
+ "dtype": "int64",
890
+ "n_missing": 0,
891
+ "min": 0.0,
892
+ "max": 1.0,
893
+ "sample": 0.0
894
+ },
895
+ "FLAG_DOCUMENT_16": {
896
+ "dtype": "int64",
897
+ "n_missing": 0,
898
+ "min": 0.0,
899
+ "max": 1.0,
900
+ "sample": 0.0
901
+ },
902
+ "FLAG_DOCUMENT_17": {
903
+ "dtype": "int64",
904
+ "n_missing": 0,
905
+ "min": 0.0,
906
+ "max": 1.0,
907
+ "sample": 0.0
908
+ },
909
+ "FLAG_DOCUMENT_18": {
910
+ "dtype": "int64",
911
+ "n_missing": 0,
912
+ "min": 0.0,
913
+ "max": 1.0,
914
+ "sample": 0.0
915
+ },
916
+ "FLAG_DOCUMENT_19": {
917
+ "dtype": "int64",
918
+ "n_missing": 0,
919
+ "min": 0.0,
920
+ "max": 1.0,
921
+ "sample": 0.0
922
+ },
923
+ "FLAG_DOCUMENT_20": {
924
+ "dtype": "int64",
925
+ "n_missing": 0,
926
+ "min": 0.0,
927
+ "max": 1.0,
928
+ "sample": 0.0
929
+ },
930
+ "FLAG_DOCUMENT_21": {
931
+ "dtype": "int64",
932
+ "n_missing": 0,
933
+ "min": 0.0,
934
+ "max": 1.0,
935
+ "sample": 0.0
936
+ },
937
+ "AMT_REQ_CREDIT_BUREAU_HOUR": {
938
+ "dtype": "float64",
939
+ "n_missing": 41519,
940
+ "min": 0.0,
941
+ "max": 4.0,
942
+ "sample": 0.0
943
+ },
944
+ "AMT_REQ_CREDIT_BUREAU_DAY": {
945
+ "dtype": "float64",
946
+ "n_missing": 41519,
947
+ "min": 0.0,
948
+ "max": 9.0,
949
+ "sample": 0.0
950
+ },
951
+ "AMT_REQ_CREDIT_BUREAU_WEEK": {
952
+ "dtype": "float64",
953
+ "n_missing": 41519,
954
+ "min": 0.0,
955
+ "max": 8.0,
956
+ "sample": 0.0
957
+ },
958
+ "AMT_REQ_CREDIT_BUREAU_MON": {
959
+ "dtype": "float64",
960
+ "n_missing": 41519,
961
+ "min": 0.0,
962
+ "max": 27.0,
963
+ "sample": 0.0
964
+ },
965
+ "AMT_REQ_CREDIT_BUREAU_QRT": {
966
+ "dtype": "float64",
967
+ "n_missing": 41519,
968
+ "min": 0.0,
969
+ "max": 261.0,
970
+ "sample": 0.0
971
+ },
972
+ "AMT_REQ_CREDIT_BUREAU_YEAR": {
973
+ "dtype": "float64",
974
+ "n_missing": 41519,
975
+ "min": 0.0,
976
+ "max": 25.0,
977
+ "sample": 1.0
978
+ }
979
+ }
models/feature_names.json ADDED
@@ -0,0 +1,770 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ "CODE_GENDER",
3
+ "FLAG_OWN_CAR",
4
+ "FLAG_OWN_REALTY",
5
+ "CNT_CHILDREN",
6
+ "AMT_INCOME_TOTAL",
7
+ "AMT_CREDIT",
8
+ "AMT_ANNUITY",
9
+ "AMT_GOODS_PRICE",
10
+ "REGION_POPULATION_RELATIVE",
11
+ "DAYS_BIRTH",
12
+ "DAYS_EMPLOYED",
13
+ "DAYS_REGISTRATION",
14
+ "DAYS_ID_PUBLISH",
15
+ "OWN_CAR_AGE",
16
+ "FLAG_MOBIL",
17
+ "FLAG_EMP_PHONE",
18
+ "FLAG_WORK_PHONE",
19
+ "FLAG_CONT_MOBILE",
20
+ "FLAG_PHONE",
21
+ "FLAG_EMAIL",
22
+ "CNT_FAM_MEMBERS",
23
+ "REGION_RATING_CLIENT",
24
+ "REGION_RATING_CLIENT_W_CITY",
25
+ "HOUR_APPR_PROCESS_START",
26
+ "REG_REGION_NOT_LIVE_REGION",
27
+ "REG_REGION_NOT_WORK_REGION",
28
+ "LIVE_REGION_NOT_WORK_REGION",
29
+ "REG_CITY_NOT_LIVE_CITY",
30
+ "REG_CITY_NOT_WORK_CITY",
31
+ "LIVE_CITY_NOT_WORK_CITY",
32
+ "EXT_SOURCE_1",
33
+ "EXT_SOURCE_2",
34
+ "EXT_SOURCE_3",
35
+ "APARTMENTS_AVG",
36
+ "BASEMENTAREA_AVG",
37
+ "YEARS_BEGINEXPLUATATION_AVG",
38
+ "YEARS_BUILD_AVG",
39
+ "COMMONAREA_AVG",
40
+ "ELEVATORS_AVG",
41
+ "ENTRANCES_AVG",
42
+ "FLOORSMAX_AVG",
43
+ "FLOORSMIN_AVG",
44
+ "LANDAREA_AVG",
45
+ "LIVINGAPARTMENTS_AVG",
46
+ "LIVINGAREA_AVG",
47
+ "NONLIVINGAPARTMENTS_AVG",
48
+ "NONLIVINGAREA_AVG",
49
+ "APARTMENTS_MODE",
50
+ "BASEMENTAREA_MODE",
51
+ "YEARS_BEGINEXPLUATATION_MODE",
52
+ "YEARS_BUILD_MODE",
53
+ "COMMONAREA_MODE",
54
+ "ELEVATORS_MODE",
55
+ "ENTRANCES_MODE",
56
+ "FLOORSMAX_MODE",
57
+ "FLOORSMIN_MODE",
58
+ "LANDAREA_MODE",
59
+ "LIVINGAPARTMENTS_MODE",
60
+ "LIVINGAREA_MODE",
61
+ "NONLIVINGAPARTMENTS_MODE",
62
+ "NONLIVINGAREA_MODE",
63
+ "APARTMENTS_MEDI",
64
+ "BASEMENTAREA_MEDI",
65
+ "YEARS_BEGINEXPLUATATION_MEDI",
66
+ "YEARS_BUILD_MEDI",
67
+ "COMMONAREA_MEDI",
68
+ "ELEVATORS_MEDI",
69
+ "ENTRANCES_MEDI",
70
+ "FLOORSMAX_MEDI",
71
+ "FLOORSMIN_MEDI",
72
+ "LANDAREA_MEDI",
73
+ "LIVINGAPARTMENTS_MEDI",
74
+ "LIVINGAREA_MEDI",
75
+ "NONLIVINGAPARTMENTS_MEDI",
76
+ "NONLIVINGAREA_MEDI",
77
+ "TOTALAREA_MODE",
78
+ "OBS_30_CNT_SOCIAL_CIRCLE",
79
+ "DEF_30_CNT_SOCIAL_CIRCLE",
80
+ "OBS_60_CNT_SOCIAL_CIRCLE",
81
+ "DEF_60_CNT_SOCIAL_CIRCLE",
82
+ "DAYS_LAST_PHONE_CHANGE",
83
+ "FLAG_DOCUMENT_2",
84
+ "FLAG_DOCUMENT_3",
85
+ "FLAG_DOCUMENT_4",
86
+ "FLAG_DOCUMENT_5",
87
+ "FLAG_DOCUMENT_6",
88
+ "FLAG_DOCUMENT_7",
89
+ "FLAG_DOCUMENT_8",
90
+ "FLAG_DOCUMENT_9",
91
+ "FLAG_DOCUMENT_10",
92
+ "FLAG_DOCUMENT_11",
93
+ "FLAG_DOCUMENT_12",
94
+ "FLAG_DOCUMENT_13",
95
+ "FLAG_DOCUMENT_14",
96
+ "FLAG_DOCUMENT_15",
97
+ "FLAG_DOCUMENT_16",
98
+ "FLAG_DOCUMENT_17",
99
+ "FLAG_DOCUMENT_18",
100
+ "FLAG_DOCUMENT_19",
101
+ "FLAG_DOCUMENT_20",
102
+ "FLAG_DOCUMENT_21",
103
+ "AMT_REQ_CREDIT_BUREAU_HOUR",
104
+ "AMT_REQ_CREDIT_BUREAU_DAY",
105
+ "AMT_REQ_CREDIT_BUREAU_WEEK",
106
+ "AMT_REQ_CREDIT_BUREAU_MON",
107
+ "AMT_REQ_CREDIT_BUREAU_QRT",
108
+ "AMT_REQ_CREDIT_BUREAU_YEAR",
109
+ "NAME_CONTRACT_TYPE_Cash loans",
110
+ "NAME_CONTRACT_TYPE_Revolving loans",
111
+ "NAME_TYPE_SUITE_Children",
112
+ "NAME_TYPE_SUITE_Family",
113
+ "NAME_TYPE_SUITE_Group of people",
114
+ "NAME_TYPE_SUITE_Other_A",
115
+ "NAME_TYPE_SUITE_Other_B",
116
+ "NAME_TYPE_SUITE_Spouse, partner",
117
+ "NAME_TYPE_SUITE_Unaccompanied",
118
+ "NAME_INCOME_TYPE_Businessman",
119
+ "NAME_INCOME_TYPE_Commercial associate",
120
+ "NAME_INCOME_TYPE_Maternity leave",
121
+ "NAME_INCOME_TYPE_Pensioner",
122
+ "NAME_INCOME_TYPE_State servant",
123
+ "NAME_INCOME_TYPE_Student",
124
+ "NAME_INCOME_TYPE_Unemployed",
125
+ "NAME_INCOME_TYPE_Working",
126
+ "NAME_EDUCATION_TYPE_Academic degree",
127
+ "NAME_EDUCATION_TYPE_Higher education",
128
+ "NAME_EDUCATION_TYPE_Incomplete higher",
129
+ "NAME_EDUCATION_TYPE_Lower secondary",
130
+ "NAME_EDUCATION_TYPE_Secondary / secondary special",
131
+ "NAME_FAMILY_STATUS_Civil marriage",
132
+ "NAME_FAMILY_STATUS_Married",
133
+ "NAME_FAMILY_STATUS_Separated",
134
+ "NAME_FAMILY_STATUS_Single / not married",
135
+ "NAME_FAMILY_STATUS_Unknown",
136
+ "NAME_FAMILY_STATUS_Widow",
137
+ "NAME_HOUSING_TYPE_Co-op apartment",
138
+ "NAME_HOUSING_TYPE_House / apartment",
139
+ "NAME_HOUSING_TYPE_Municipal apartment",
140
+ "NAME_HOUSING_TYPE_Office apartment",
141
+ "NAME_HOUSING_TYPE_Rented apartment",
142
+ "NAME_HOUSING_TYPE_With parents",
143
+ "OCCUPATION_TYPE_Accountants",
144
+ "OCCUPATION_TYPE_Cleaning staff",
145
+ "OCCUPATION_TYPE_Cooking staff",
146
+ "OCCUPATION_TYPE_Core staff",
147
+ "OCCUPATION_TYPE_Drivers",
148
+ "OCCUPATION_TYPE_HR staff",
149
+ "OCCUPATION_TYPE_High skill tech staff",
150
+ "OCCUPATION_TYPE_IT staff",
151
+ "OCCUPATION_TYPE_Laborers",
152
+ "OCCUPATION_TYPE_Low-skill Laborers",
153
+ "OCCUPATION_TYPE_Managers",
154
+ "OCCUPATION_TYPE_Medicine staff",
155
+ "OCCUPATION_TYPE_Private service staff",
156
+ "OCCUPATION_TYPE_Realty agents",
157
+ "OCCUPATION_TYPE_Sales staff",
158
+ "OCCUPATION_TYPE_Secretaries",
159
+ "OCCUPATION_TYPE_Security staff",
160
+ "OCCUPATION_TYPE_Waiters/barmen staff",
161
+ "WEEKDAY_APPR_PROCESS_START_FRIDAY",
162
+ "WEEKDAY_APPR_PROCESS_START_MONDAY",
163
+ "WEEKDAY_APPR_PROCESS_START_SATURDAY",
164
+ "WEEKDAY_APPR_PROCESS_START_SUNDAY",
165
+ "WEEKDAY_APPR_PROCESS_START_THURSDAY",
166
+ "WEEKDAY_APPR_PROCESS_START_TUESDAY",
167
+ "WEEKDAY_APPR_PROCESS_START_WEDNESDAY",
168
+ "ORGANIZATION_TYPE_Advertising",
169
+ "ORGANIZATION_TYPE_Agriculture",
170
+ "ORGANIZATION_TYPE_Bank",
171
+ "ORGANIZATION_TYPE_Business Entity Type 1",
172
+ "ORGANIZATION_TYPE_Business Entity Type 2",
173
+ "ORGANIZATION_TYPE_Business Entity Type 3",
174
+ "ORGANIZATION_TYPE_Cleaning",
175
+ "ORGANIZATION_TYPE_Construction",
176
+ "ORGANIZATION_TYPE_Culture",
177
+ "ORGANIZATION_TYPE_Electricity",
178
+ "ORGANIZATION_TYPE_Emergency",
179
+ "ORGANIZATION_TYPE_Government",
180
+ "ORGANIZATION_TYPE_Hotel",
181
+ "ORGANIZATION_TYPE_Housing",
182
+ "ORGANIZATION_TYPE_Industry: type 1",
183
+ "ORGANIZATION_TYPE_Industry: type 10",
184
+ "ORGANIZATION_TYPE_Industry: type 11",
185
+ "ORGANIZATION_TYPE_Industry: type 12",
186
+ "ORGANIZATION_TYPE_Industry: type 13",
187
+ "ORGANIZATION_TYPE_Industry: type 2",
188
+ "ORGANIZATION_TYPE_Industry: type 3",
189
+ "ORGANIZATION_TYPE_Industry: type 4",
190
+ "ORGANIZATION_TYPE_Industry: type 5",
191
+ "ORGANIZATION_TYPE_Industry: type 6",
192
+ "ORGANIZATION_TYPE_Industry: type 7",
193
+ "ORGANIZATION_TYPE_Industry: type 8",
194
+ "ORGANIZATION_TYPE_Industry: type 9",
195
+ "ORGANIZATION_TYPE_Insurance",
196
+ "ORGANIZATION_TYPE_Kindergarten",
197
+ "ORGANIZATION_TYPE_Legal Services",
198
+ "ORGANIZATION_TYPE_Medicine",
199
+ "ORGANIZATION_TYPE_Military",
200
+ "ORGANIZATION_TYPE_Mobile",
201
+ "ORGANIZATION_TYPE_Other",
202
+ "ORGANIZATION_TYPE_Police",
203
+ "ORGANIZATION_TYPE_Postal",
204
+ "ORGANIZATION_TYPE_Realtor",
205
+ "ORGANIZATION_TYPE_Religion",
206
+ "ORGANIZATION_TYPE_Restaurant",
207
+ "ORGANIZATION_TYPE_School",
208
+ "ORGANIZATION_TYPE_Security",
209
+ "ORGANIZATION_TYPE_Security Ministries",
210
+ "ORGANIZATION_TYPE_Self-employed",
211
+ "ORGANIZATION_TYPE_Services",
212
+ "ORGANIZATION_TYPE_Telecom",
213
+ "ORGANIZATION_TYPE_Trade: type 1",
214
+ "ORGANIZATION_TYPE_Trade: type 2",
215
+ "ORGANIZATION_TYPE_Trade: type 3",
216
+ "ORGANIZATION_TYPE_Trade: type 4",
217
+ "ORGANIZATION_TYPE_Trade: type 5",
218
+ "ORGANIZATION_TYPE_Trade: type 6",
219
+ "ORGANIZATION_TYPE_Trade: type 7",
220
+ "ORGANIZATION_TYPE_Transport: type 1",
221
+ "ORGANIZATION_TYPE_Transport: type 2",
222
+ "ORGANIZATION_TYPE_Transport: type 3",
223
+ "ORGANIZATION_TYPE_Transport: type 4",
224
+ "ORGANIZATION_TYPE_University",
225
+ "ORGANIZATION_TYPE_XNA",
226
+ "FONDKAPREMONT_MODE_not specified",
227
+ "FONDKAPREMONT_MODE_org spec account",
228
+ "FONDKAPREMONT_MODE_reg oper account",
229
+ "FONDKAPREMONT_MODE_reg oper spec account",
230
+ "HOUSETYPE_MODE_block of flats",
231
+ "HOUSETYPE_MODE_specific housing",
232
+ "HOUSETYPE_MODE_terraced house",
233
+ "WALLSMATERIAL_MODE_Block",
234
+ "WALLSMATERIAL_MODE_Mixed",
235
+ "WALLSMATERIAL_MODE_Monolithic",
236
+ "WALLSMATERIAL_MODE_Others",
237
+ "WALLSMATERIAL_MODE_Panel",
238
+ "WALLSMATERIAL_MODE_Stone, brick",
239
+ "WALLSMATERIAL_MODE_Wooden",
240
+ "EMERGENCYSTATE_MODE_No",
241
+ "EMERGENCYSTATE_MODE_Yes",
242
+ "DAYS_EMPLOYED_PERC",
243
+ "INCOME_CREDIT_PERC",
244
+ "INCOME_PER_PERSON",
245
+ "ANNUITY_INCOME_PERC",
246
+ "PAYMENT_RATE",
247
+ "BURO_DAYS_CREDIT_MIN",
248
+ "BURO_DAYS_CREDIT_MAX",
249
+ "BURO_DAYS_CREDIT_MEAN",
250
+ "BURO_DAYS_CREDIT_VAR",
251
+ "BURO_DAYS_CREDIT_ENDDATE_MIN",
252
+ "BURO_DAYS_CREDIT_ENDDATE_MAX",
253
+ "BURO_DAYS_CREDIT_ENDDATE_MEAN",
254
+ "BURO_DAYS_CREDIT_UPDATE_MEAN",
255
+ "BURO_CREDIT_DAY_OVERDUE_MAX",
256
+ "BURO_CREDIT_DAY_OVERDUE_MEAN",
257
+ "BURO_AMT_CREDIT_MAX_OVERDUE_MEAN",
258
+ "BURO_AMT_CREDIT_SUM_MAX",
259
+ "BURO_AMT_CREDIT_SUM_MEAN",
260
+ "BURO_AMT_CREDIT_SUM_SUM",
261
+ "BURO_AMT_CREDIT_SUM_DEBT_MAX",
262
+ "BURO_AMT_CREDIT_SUM_DEBT_MEAN",
263
+ "BURO_AMT_CREDIT_SUM_DEBT_SUM",
264
+ "BURO_AMT_CREDIT_SUM_OVERDUE_MEAN",
265
+ "BURO_AMT_CREDIT_SUM_LIMIT_MEAN",
266
+ "BURO_AMT_CREDIT_SUM_LIMIT_SUM",
267
+ "BURO_AMT_ANNUITY_MAX",
268
+ "BURO_AMT_ANNUITY_MEAN",
269
+ "BURO_CNT_CREDIT_PROLONG_SUM",
270
+ "BURO_MONTHS_BALANCE_MIN_MIN",
271
+ "BURO_MONTHS_BALANCE_MAX_MAX",
272
+ "BURO_MONTHS_BALANCE_SIZE_MEAN",
273
+ "BURO_MONTHS_BALANCE_SIZE_SUM",
274
+ "BURO_CREDIT_ACTIVE_Active_MEAN",
275
+ "BURO_CREDIT_ACTIVE_Bad debt_MEAN",
276
+ "BURO_CREDIT_ACTIVE_Closed_MEAN",
277
+ "BURO_CREDIT_ACTIVE_Sold_MEAN",
278
+ "BURO_CREDIT_ACTIVE_nan_MEAN",
279
+ "BURO_CREDIT_CURRENCY_currency 1_MEAN",
280
+ "BURO_CREDIT_CURRENCY_currency 2_MEAN",
281
+ "BURO_CREDIT_CURRENCY_currency 3_MEAN",
282
+ "BURO_CREDIT_CURRENCY_currency 4_MEAN",
283
+ "BURO_CREDIT_CURRENCY_nan_MEAN",
284
+ "BURO_CREDIT_TYPE_Another type of loan_MEAN",
285
+ "BURO_CREDIT_TYPE_Car loan_MEAN",
286
+ "BURO_CREDIT_TYPE_Cash loan (non-earmarked)_MEAN",
287
+ "BURO_CREDIT_TYPE_Consumer credit_MEAN",
288
+ "BURO_CREDIT_TYPE_Credit card_MEAN",
289
+ "BURO_CREDIT_TYPE_Interbank credit_MEAN",
290
+ "BURO_CREDIT_TYPE_Loan for business development_MEAN",
291
+ "BURO_CREDIT_TYPE_Loan for purchase of shares (margin lending)_MEAN",
292
+ "BURO_CREDIT_TYPE_Loan for the purchase of equipment_MEAN",
293
+ "BURO_CREDIT_TYPE_Loan for working capital replenishment_MEAN",
294
+ "BURO_CREDIT_TYPE_Microloan_MEAN",
295
+ "BURO_CREDIT_TYPE_Mobile operator loan_MEAN",
296
+ "BURO_CREDIT_TYPE_Mortgage_MEAN",
297
+ "BURO_CREDIT_TYPE_Real estate loan_MEAN",
298
+ "BURO_CREDIT_TYPE_Unknown type of loan_MEAN",
299
+ "BURO_CREDIT_TYPE_nan_MEAN",
300
+ "BURO_STATUS_0_MEAN_MEAN",
301
+ "BURO_STATUS_1_MEAN_MEAN",
302
+ "BURO_STATUS_2_MEAN_MEAN",
303
+ "BURO_STATUS_3_MEAN_MEAN",
304
+ "BURO_STATUS_4_MEAN_MEAN",
305
+ "BURO_STATUS_5_MEAN_MEAN",
306
+ "BURO_STATUS_C_MEAN_MEAN",
307
+ "BURO_STATUS_X_MEAN_MEAN",
308
+ "BURO_STATUS_nan_MEAN_MEAN",
309
+ "ACTIVE_DAYS_CREDIT_MIN",
310
+ "ACTIVE_DAYS_CREDIT_MAX",
311
+ "ACTIVE_DAYS_CREDIT_MEAN",
312
+ "ACTIVE_DAYS_CREDIT_VAR",
313
+ "ACTIVE_DAYS_CREDIT_ENDDATE_MIN",
314
+ "ACTIVE_DAYS_CREDIT_ENDDATE_MAX",
315
+ "ACTIVE_DAYS_CREDIT_ENDDATE_MEAN",
316
+ "ACTIVE_DAYS_CREDIT_UPDATE_MEAN",
317
+ "ACTIVE_CREDIT_DAY_OVERDUE_MAX",
318
+ "ACTIVE_CREDIT_DAY_OVERDUE_MEAN",
319
+ "ACTIVE_AMT_CREDIT_MAX_OVERDUE_MEAN",
320
+ "ACTIVE_AMT_CREDIT_SUM_MAX",
321
+ "ACTIVE_AMT_CREDIT_SUM_MEAN",
322
+ "ACTIVE_AMT_CREDIT_SUM_SUM",
323
+ "ACTIVE_AMT_CREDIT_SUM_DEBT_MAX",
324
+ "ACTIVE_AMT_CREDIT_SUM_DEBT_MEAN",
325
+ "ACTIVE_AMT_CREDIT_SUM_DEBT_SUM",
326
+ "ACTIVE_AMT_CREDIT_SUM_OVERDUE_MEAN",
327
+ "ACTIVE_AMT_CREDIT_SUM_LIMIT_MEAN",
328
+ "ACTIVE_AMT_CREDIT_SUM_LIMIT_SUM",
329
+ "ACTIVE_AMT_ANNUITY_MAX",
330
+ "ACTIVE_AMT_ANNUITY_MEAN",
331
+ "ACTIVE_CNT_CREDIT_PROLONG_SUM",
332
+ "ACTIVE_MONTHS_BALANCE_MIN_MIN",
333
+ "ACTIVE_MONTHS_BALANCE_MAX_MAX",
334
+ "ACTIVE_MONTHS_BALANCE_SIZE_MEAN",
335
+ "ACTIVE_MONTHS_BALANCE_SIZE_SUM",
336
+ "CLOSED_DAYS_CREDIT_MIN",
337
+ "CLOSED_DAYS_CREDIT_MAX",
338
+ "CLOSED_DAYS_CREDIT_MEAN",
339
+ "CLOSED_DAYS_CREDIT_VAR",
340
+ "CLOSED_DAYS_CREDIT_ENDDATE_MIN",
341
+ "CLOSED_DAYS_CREDIT_ENDDATE_MAX",
342
+ "CLOSED_DAYS_CREDIT_ENDDATE_MEAN",
343
+ "CLOSED_DAYS_CREDIT_UPDATE_MEAN",
344
+ "CLOSED_CREDIT_DAY_OVERDUE_MAX",
345
+ "CLOSED_CREDIT_DAY_OVERDUE_MEAN",
346
+ "CLOSED_AMT_CREDIT_MAX_OVERDUE_MEAN",
347
+ "CLOSED_AMT_CREDIT_SUM_MAX",
348
+ "CLOSED_AMT_CREDIT_SUM_MEAN",
349
+ "CLOSED_AMT_CREDIT_SUM_SUM",
350
+ "CLOSED_AMT_CREDIT_SUM_DEBT_MAX",
351
+ "CLOSED_AMT_CREDIT_SUM_DEBT_MEAN",
352
+ "CLOSED_AMT_CREDIT_SUM_DEBT_SUM",
353
+ "CLOSED_AMT_CREDIT_SUM_OVERDUE_MEAN",
354
+ "CLOSED_AMT_CREDIT_SUM_LIMIT_MEAN",
355
+ "CLOSED_AMT_CREDIT_SUM_LIMIT_SUM",
356
+ "CLOSED_AMT_ANNUITY_MAX",
357
+ "CLOSED_AMT_ANNUITY_MEAN",
358
+ "CLOSED_CNT_CREDIT_PROLONG_SUM",
359
+ "CLOSED_MONTHS_BALANCE_MIN_MIN",
360
+ "CLOSED_MONTHS_BALANCE_MAX_MAX",
361
+ "CLOSED_MONTHS_BALANCE_SIZE_MEAN",
362
+ "CLOSED_MONTHS_BALANCE_SIZE_SUM",
363
+ "PREV_AMT_ANNUITY_MIN",
364
+ "PREV_AMT_ANNUITY_MAX",
365
+ "PREV_AMT_ANNUITY_MEAN",
366
+ "PREV_AMT_APPLICATION_MIN",
367
+ "PREV_AMT_APPLICATION_MAX",
368
+ "PREV_AMT_APPLICATION_MEAN",
369
+ "PREV_AMT_CREDIT_MIN",
370
+ "PREV_AMT_CREDIT_MAX",
371
+ "PREV_AMT_CREDIT_MEAN",
372
+ "PREV_APP_CREDIT_PERC_MIN",
373
+ "PREV_APP_CREDIT_PERC_MAX",
374
+ "PREV_APP_CREDIT_PERC_MEAN",
375
+ "PREV_APP_CREDIT_PERC_VAR",
376
+ "PREV_AMT_DOWN_PAYMENT_MIN",
377
+ "PREV_AMT_DOWN_PAYMENT_MAX",
378
+ "PREV_AMT_DOWN_PAYMENT_MEAN",
379
+ "PREV_AMT_GOODS_PRICE_MIN",
380
+ "PREV_AMT_GOODS_PRICE_MAX",
381
+ "PREV_AMT_GOODS_PRICE_MEAN",
382
+ "PREV_HOUR_APPR_PROCESS_START_MIN",
383
+ "PREV_HOUR_APPR_PROCESS_START_MAX",
384
+ "PREV_HOUR_APPR_PROCESS_START_MEAN",
385
+ "PREV_RATE_DOWN_PAYMENT_MIN",
386
+ "PREV_RATE_DOWN_PAYMENT_MAX",
387
+ "PREV_RATE_DOWN_PAYMENT_MEAN",
388
+ "PREV_DAYS_DECISION_MIN",
389
+ "PREV_DAYS_DECISION_MAX",
390
+ "PREV_DAYS_DECISION_MEAN",
391
+ "PREV_CNT_PAYMENT_MEAN",
392
+ "PREV_CNT_PAYMENT_SUM",
393
+ "PREV_NAME_CONTRACT_TYPE_Cash loans_MEAN",
394
+ "PREV_NAME_CONTRACT_TYPE_Consumer loans_MEAN",
395
+ "PREV_NAME_CONTRACT_TYPE_Revolving loans_MEAN",
396
+ "PREV_NAME_CONTRACT_TYPE_XNA_MEAN",
397
+ "PREV_NAME_CONTRACT_TYPE_nan_MEAN",
398
+ "PREV_WEEKDAY_APPR_PROCESS_START_FRIDAY_MEAN",
399
+ "PREV_WEEKDAY_APPR_PROCESS_START_MONDAY_MEAN",
400
+ "PREV_WEEKDAY_APPR_PROCESS_START_SATURDAY_MEAN",
401
+ "PREV_WEEKDAY_APPR_PROCESS_START_SUNDAY_MEAN",
402
+ "PREV_WEEKDAY_APPR_PROCESS_START_THURSDAY_MEAN",
403
+ "PREV_WEEKDAY_APPR_PROCESS_START_TUESDAY_MEAN",
404
+ "PREV_WEEKDAY_APPR_PROCESS_START_WEDNESDAY_MEAN",
405
+ "PREV_WEEKDAY_APPR_PROCESS_START_nan_MEAN",
406
+ "PREV_FLAG_LAST_APPL_PER_CONTRACT_N_MEAN",
407
+ "PREV_FLAG_LAST_APPL_PER_CONTRACT_Y_MEAN",
408
+ "PREV_FLAG_LAST_APPL_PER_CONTRACT_nan_MEAN",
409
+ "PREV_NAME_CASH_LOAN_PURPOSE_Building a house or an annex_MEAN",
410
+ "PREV_NAME_CASH_LOAN_PURPOSE_Business development_MEAN",
411
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a garage_MEAN",
412
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a holiday home / land_MEAN",
413
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a home_MEAN",
414
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a new car_MEAN",
415
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a used car_MEAN",
416
+ "PREV_NAME_CASH_LOAN_PURPOSE_Car repairs_MEAN",
417
+ "PREV_NAME_CASH_LOAN_PURPOSE_Education_MEAN",
418
+ "PREV_NAME_CASH_LOAN_PURPOSE_Everyday expenses_MEAN",
419
+ "PREV_NAME_CASH_LOAN_PURPOSE_Furniture_MEAN",
420
+ "PREV_NAME_CASH_LOAN_PURPOSE_Gasification / water supply_MEAN",
421
+ "PREV_NAME_CASH_LOAN_PURPOSE_Hobby_MEAN",
422
+ "PREV_NAME_CASH_LOAN_PURPOSE_Journey_MEAN",
423
+ "PREV_NAME_CASH_LOAN_PURPOSE_Medicine_MEAN",
424
+ "PREV_NAME_CASH_LOAN_PURPOSE_Money for a third person_MEAN",
425
+ "PREV_NAME_CASH_LOAN_PURPOSE_Other_MEAN",
426
+ "PREV_NAME_CASH_LOAN_PURPOSE_Payments on other loans_MEAN",
427
+ "PREV_NAME_CASH_LOAN_PURPOSE_Purchase of electronic equipment_MEAN",
428
+ "PREV_NAME_CASH_LOAN_PURPOSE_Refusal to name the goal_MEAN",
429
+ "PREV_NAME_CASH_LOAN_PURPOSE_Repairs_MEAN",
430
+ "PREV_NAME_CASH_LOAN_PURPOSE_Urgent needs_MEAN",
431
+ "PREV_NAME_CASH_LOAN_PURPOSE_Wedding / gift / holiday_MEAN",
432
+ "PREV_NAME_CASH_LOAN_PURPOSE_XAP_MEAN",
433
+ "PREV_NAME_CASH_LOAN_PURPOSE_XNA_MEAN",
434
+ "PREV_NAME_CASH_LOAN_PURPOSE_nan_MEAN",
435
+ "PREV_NAME_CONTRACT_STATUS_Approved_MEAN",
436
+ "PREV_NAME_CONTRACT_STATUS_Canceled_MEAN",
437
+ "PREV_NAME_CONTRACT_STATUS_Refused_MEAN",
438
+ "PREV_NAME_CONTRACT_STATUS_Unused offer_MEAN",
439
+ "PREV_NAME_CONTRACT_STATUS_nan_MEAN",
440
+ "PREV_NAME_PAYMENT_TYPE_Cash through the bank_MEAN",
441
+ "PREV_NAME_PAYMENT_TYPE_Cashless from the account of the employer_MEAN",
442
+ "PREV_NAME_PAYMENT_TYPE_Non-cash from your account_MEAN",
443
+ "PREV_NAME_PAYMENT_TYPE_XNA_MEAN",
444
+ "PREV_NAME_PAYMENT_TYPE_nan_MEAN",
445
+ "PREV_CODE_REJECT_REASON_CLIENT_MEAN",
446
+ "PREV_CODE_REJECT_REASON_HC_MEAN",
447
+ "PREV_CODE_REJECT_REASON_LIMIT_MEAN",
448
+ "PREV_CODE_REJECT_REASON_SCO_MEAN",
449
+ "PREV_CODE_REJECT_REASON_SCOFR_MEAN",
450
+ "PREV_CODE_REJECT_REASON_SYSTEM_MEAN",
451
+ "PREV_CODE_REJECT_REASON_VERIF_MEAN",
452
+ "PREV_CODE_REJECT_REASON_XAP_MEAN",
453
+ "PREV_CODE_REJECT_REASON_XNA_MEAN",
454
+ "PREV_CODE_REJECT_REASON_nan_MEAN",
455
+ "PREV_NAME_TYPE_SUITE_Children_MEAN",
456
+ "PREV_NAME_TYPE_SUITE_Family_MEAN",
457
+ "PREV_NAME_TYPE_SUITE_Group of people_MEAN",
458
+ "PREV_NAME_TYPE_SUITE_Other_A_MEAN",
459
+ "PREV_NAME_TYPE_SUITE_Other_B_MEAN",
460
+ "PREV_NAME_TYPE_SUITE_Spouse, partner_MEAN",
461
+ "PREV_NAME_TYPE_SUITE_Unaccompanied_MEAN",
462
+ "PREV_NAME_TYPE_SUITE_nan_MEAN",
463
+ "PREV_NAME_CLIENT_TYPE_New_MEAN",
464
+ "PREV_NAME_CLIENT_TYPE_Refreshed_MEAN",
465
+ "PREV_NAME_CLIENT_TYPE_Repeater_MEAN",
466
+ "PREV_NAME_CLIENT_TYPE_XNA_MEAN",
467
+ "PREV_NAME_CLIENT_TYPE_nan_MEAN",
468
+ "PREV_NAME_GOODS_CATEGORY_Additional Service_MEAN",
469
+ "PREV_NAME_GOODS_CATEGORY_Animals_MEAN",
470
+ "PREV_NAME_GOODS_CATEGORY_Audio/Video_MEAN",
471
+ "PREV_NAME_GOODS_CATEGORY_Auto Accessories_MEAN",
472
+ "PREV_NAME_GOODS_CATEGORY_Clothing and Accessories_MEAN",
473
+ "PREV_NAME_GOODS_CATEGORY_Computers_MEAN",
474
+ "PREV_NAME_GOODS_CATEGORY_Construction Materials_MEAN",
475
+ "PREV_NAME_GOODS_CATEGORY_Consumer Electronics_MEAN",
476
+ "PREV_NAME_GOODS_CATEGORY_Direct Sales_MEAN",
477
+ "PREV_NAME_GOODS_CATEGORY_Education_MEAN",
478
+ "PREV_NAME_GOODS_CATEGORY_Fitness_MEAN",
479
+ "PREV_NAME_GOODS_CATEGORY_Furniture_MEAN",
480
+ "PREV_NAME_GOODS_CATEGORY_Gardening_MEAN",
481
+ "PREV_NAME_GOODS_CATEGORY_Homewares_MEAN",
482
+ "PREV_NAME_GOODS_CATEGORY_House Construction_MEAN",
483
+ "PREV_NAME_GOODS_CATEGORY_Insurance_MEAN",
484
+ "PREV_NAME_GOODS_CATEGORY_Jewelry_MEAN",
485
+ "PREV_NAME_GOODS_CATEGORY_Medical Supplies_MEAN",
486
+ "PREV_NAME_GOODS_CATEGORY_Medicine_MEAN",
487
+ "PREV_NAME_GOODS_CATEGORY_Mobile_MEAN",
488
+ "PREV_NAME_GOODS_CATEGORY_Office Appliances_MEAN",
489
+ "PREV_NAME_GOODS_CATEGORY_Other_MEAN",
490
+ "PREV_NAME_GOODS_CATEGORY_Photo / Cinema Equipment_MEAN",
491
+ "PREV_NAME_GOODS_CATEGORY_Sport and Leisure_MEAN",
492
+ "PREV_NAME_GOODS_CATEGORY_Tourism_MEAN",
493
+ "PREV_NAME_GOODS_CATEGORY_Vehicles_MEAN",
494
+ "PREV_NAME_GOODS_CATEGORY_Weapon_MEAN",
495
+ "PREV_NAME_GOODS_CATEGORY_XNA_MEAN",
496
+ "PREV_NAME_GOODS_CATEGORY_nan_MEAN",
497
+ "PREV_NAME_PORTFOLIO_Cards_MEAN",
498
+ "PREV_NAME_PORTFOLIO_Cars_MEAN",
499
+ "PREV_NAME_PORTFOLIO_Cash_MEAN",
500
+ "PREV_NAME_PORTFOLIO_POS_MEAN",
501
+ "PREV_NAME_PORTFOLIO_XNA_MEAN",
502
+ "PREV_NAME_PORTFOLIO_nan_MEAN",
503
+ "PREV_NAME_PRODUCT_TYPE_XNA_MEAN",
504
+ "PREV_NAME_PRODUCT_TYPE_walk-in_MEAN",
505
+ "PREV_NAME_PRODUCT_TYPE_x-sell_MEAN",
506
+ "PREV_NAME_PRODUCT_TYPE_nan_MEAN",
507
+ "PREV_CHANNEL_TYPE_AP+ (Cash loan)_MEAN",
508
+ "PREV_CHANNEL_TYPE_Car dealer_MEAN",
509
+ "PREV_CHANNEL_TYPE_Channel of corporate sales_MEAN",
510
+ "PREV_CHANNEL_TYPE_Contact center_MEAN",
511
+ "PREV_CHANNEL_TYPE_Country-wide_MEAN",
512
+ "PREV_CHANNEL_TYPE_Credit and cash offices_MEAN",
513
+ "PREV_CHANNEL_TYPE_Regional / Local_MEAN",
514
+ "PREV_CHANNEL_TYPE_Stone_MEAN",
515
+ "PREV_CHANNEL_TYPE_nan_MEAN",
516
+ "PREV_NAME_SELLER_INDUSTRY_Auto technology_MEAN",
517
+ "PREV_NAME_SELLER_INDUSTRY_Clothing_MEAN",
518
+ "PREV_NAME_SELLER_INDUSTRY_Connectivity_MEAN",
519
+ "PREV_NAME_SELLER_INDUSTRY_Construction_MEAN",
520
+ "PREV_NAME_SELLER_INDUSTRY_Consumer electronics_MEAN",
521
+ "PREV_NAME_SELLER_INDUSTRY_Furniture_MEAN",
522
+ "PREV_NAME_SELLER_INDUSTRY_Industry_MEAN",
523
+ "PREV_NAME_SELLER_INDUSTRY_Jewelry_MEAN",
524
+ "PREV_NAME_SELLER_INDUSTRY_MLM partners_MEAN",
525
+ "PREV_NAME_SELLER_INDUSTRY_Tourism_MEAN",
526
+ "PREV_NAME_SELLER_INDUSTRY_XNA_MEAN",
527
+ "PREV_NAME_SELLER_INDUSTRY_nan_MEAN",
528
+ "PREV_NAME_YIELD_GROUP_XNA_MEAN",
529
+ "PREV_NAME_YIELD_GROUP_high_MEAN",
530
+ "PREV_NAME_YIELD_GROUP_low_action_MEAN",
531
+ "PREV_NAME_YIELD_GROUP_low_normal_MEAN",
532
+ "PREV_NAME_YIELD_GROUP_middle_MEAN",
533
+ "PREV_NAME_YIELD_GROUP_nan_MEAN",
534
+ "PREV_PRODUCT_COMBINATION_Card Street_MEAN",
535
+ "PREV_PRODUCT_COMBINATION_Card X-Sell_MEAN",
536
+ "PREV_PRODUCT_COMBINATION_Cash_MEAN",
537
+ "PREV_PRODUCT_COMBINATION_Cash Street: high_MEAN",
538
+ "PREV_PRODUCT_COMBINATION_Cash Street: low_MEAN",
539
+ "PREV_PRODUCT_COMBINATION_Cash Street: middle_MEAN",
540
+ "PREV_PRODUCT_COMBINATION_Cash X-Sell: high_MEAN",
541
+ "PREV_PRODUCT_COMBINATION_Cash X-Sell: low_MEAN",
542
+ "PREV_PRODUCT_COMBINATION_Cash X-Sell: middle_MEAN",
543
+ "PREV_PRODUCT_COMBINATION_POS household with interest_MEAN",
544
+ "PREV_PRODUCT_COMBINATION_POS household without interest_MEAN",
545
+ "PREV_PRODUCT_COMBINATION_POS industry with interest_MEAN",
546
+ "PREV_PRODUCT_COMBINATION_POS industry without interest_MEAN",
547
+ "PREV_PRODUCT_COMBINATION_POS mobile with interest_MEAN",
548
+ "PREV_PRODUCT_COMBINATION_POS mobile without interest_MEAN",
549
+ "PREV_PRODUCT_COMBINATION_POS other with interest_MEAN",
550
+ "PREV_PRODUCT_COMBINATION_POS others without interest_MEAN",
551
+ "PREV_PRODUCT_COMBINATION_nan_MEAN",
552
+ "APPROVED_AMT_ANNUITY_MIN",
553
+ "APPROVED_AMT_ANNUITY_MAX",
554
+ "APPROVED_AMT_ANNUITY_MEAN",
555
+ "APPROVED_AMT_APPLICATION_MIN",
556
+ "APPROVED_AMT_APPLICATION_MAX",
557
+ "APPROVED_AMT_APPLICATION_MEAN",
558
+ "APPROVED_AMT_CREDIT_MIN",
559
+ "APPROVED_AMT_CREDIT_MAX",
560
+ "APPROVED_AMT_CREDIT_MEAN",
561
+ "APPROVED_APP_CREDIT_PERC_MIN",
562
+ "APPROVED_APP_CREDIT_PERC_MAX",
563
+ "APPROVED_APP_CREDIT_PERC_MEAN",
564
+ "APPROVED_APP_CREDIT_PERC_VAR",
565
+ "APPROVED_AMT_DOWN_PAYMENT_MIN",
566
+ "APPROVED_AMT_DOWN_PAYMENT_MAX",
567
+ "APPROVED_AMT_DOWN_PAYMENT_MEAN",
568
+ "APPROVED_AMT_GOODS_PRICE_MIN",
569
+ "APPROVED_AMT_GOODS_PRICE_MAX",
570
+ "APPROVED_AMT_GOODS_PRICE_MEAN",
571
+ "APPROVED_HOUR_APPR_PROCESS_START_MIN",
572
+ "APPROVED_HOUR_APPR_PROCESS_START_MAX",
573
+ "APPROVED_HOUR_APPR_PROCESS_START_MEAN",
574
+ "APPROVED_RATE_DOWN_PAYMENT_MIN",
575
+ "APPROVED_RATE_DOWN_PAYMENT_MAX",
576
+ "APPROVED_RATE_DOWN_PAYMENT_MEAN",
577
+ "APPROVED_DAYS_DECISION_MIN",
578
+ "APPROVED_DAYS_DECISION_MAX",
579
+ "APPROVED_DAYS_DECISION_MEAN",
580
+ "APPROVED_CNT_PAYMENT_MEAN",
581
+ "APPROVED_CNT_PAYMENT_SUM",
582
+ "REFUSED_AMT_ANNUITY_MIN",
583
+ "REFUSED_AMT_ANNUITY_MAX",
584
+ "REFUSED_AMT_ANNUITY_MEAN",
585
+ "REFUSED_AMT_APPLICATION_MIN",
586
+ "REFUSED_AMT_APPLICATION_MAX",
587
+ "REFUSED_AMT_APPLICATION_MEAN",
588
+ "REFUSED_AMT_CREDIT_MIN",
589
+ "REFUSED_AMT_CREDIT_MAX",
590
+ "REFUSED_AMT_CREDIT_MEAN",
591
+ "REFUSED_APP_CREDIT_PERC_MIN",
592
+ "REFUSED_APP_CREDIT_PERC_MAX",
593
+ "REFUSED_APP_CREDIT_PERC_MEAN",
594
+ "REFUSED_APP_CREDIT_PERC_VAR",
595
+ "REFUSED_AMT_DOWN_PAYMENT_MIN",
596
+ "REFUSED_AMT_DOWN_PAYMENT_MAX",
597
+ "REFUSED_AMT_DOWN_PAYMENT_MEAN",
598
+ "REFUSED_AMT_GOODS_PRICE_MIN",
599
+ "REFUSED_AMT_GOODS_PRICE_MAX",
600
+ "REFUSED_AMT_GOODS_PRICE_MEAN",
601
+ "REFUSED_HOUR_APPR_PROCESS_START_MIN",
602
+ "REFUSED_HOUR_APPR_PROCESS_START_MAX",
603
+ "REFUSED_HOUR_APPR_PROCESS_START_MEAN",
604
+ "REFUSED_RATE_DOWN_PAYMENT_MIN",
605
+ "REFUSED_RATE_DOWN_PAYMENT_MAX",
606
+ "REFUSED_RATE_DOWN_PAYMENT_MEAN",
607
+ "REFUSED_DAYS_DECISION_MIN",
608
+ "REFUSED_DAYS_DECISION_MAX",
609
+ "REFUSED_DAYS_DECISION_MEAN",
610
+ "REFUSED_CNT_PAYMENT_MEAN",
611
+ "REFUSED_CNT_PAYMENT_SUM",
612
+ "POS_MONTHS_BALANCE_MAX",
613
+ "POS_MONTHS_BALANCE_MEAN",
614
+ "POS_MONTHS_BALANCE_SIZE",
615
+ "POS_SK_DPD_MAX",
616
+ "POS_SK_DPD_MEAN",
617
+ "POS_SK_DPD_DEF_MAX",
618
+ "POS_SK_DPD_DEF_MEAN",
619
+ "POS_NAME_CONTRACT_STATUS_Active_MEAN",
620
+ "POS_NAME_CONTRACT_STATUS_Amortized debt_MEAN",
621
+ "POS_NAME_CONTRACT_STATUS_Approved_MEAN",
622
+ "POS_NAME_CONTRACT_STATUS_Canceled_MEAN",
623
+ "POS_NAME_CONTRACT_STATUS_Completed_MEAN",
624
+ "POS_NAME_CONTRACT_STATUS_Demand_MEAN",
625
+ "POS_NAME_CONTRACT_STATUS_Returned to the store_MEAN",
626
+ "POS_NAME_CONTRACT_STATUS_Signed_MEAN",
627
+ "POS_NAME_CONTRACT_STATUS_XNA_MEAN",
628
+ "POS_NAME_CONTRACT_STATUS_nan_MEAN",
629
+ "POS_COUNT",
630
+ "INSTAL_NUM_INSTALMENT_VERSION_NUNIQUE",
631
+ "INSTAL_DPD_MAX",
632
+ "INSTAL_DPD_MEAN",
633
+ "INSTAL_DPD_SUM",
634
+ "INSTAL_DBD_MAX",
635
+ "INSTAL_DBD_MEAN",
636
+ "INSTAL_DBD_SUM",
637
+ "INSTAL_PAYMENT_PERC_MAX",
638
+ "INSTAL_PAYMENT_PERC_MEAN",
639
+ "INSTAL_PAYMENT_PERC_SUM",
640
+ "INSTAL_PAYMENT_PERC_VAR",
641
+ "INSTAL_PAYMENT_DIFF_MAX",
642
+ "INSTAL_PAYMENT_DIFF_MEAN",
643
+ "INSTAL_PAYMENT_DIFF_SUM",
644
+ "INSTAL_PAYMENT_DIFF_VAR",
645
+ "INSTAL_AMT_INSTALMENT_MAX",
646
+ "INSTAL_AMT_INSTALMENT_MEAN",
647
+ "INSTAL_AMT_INSTALMENT_SUM",
648
+ "INSTAL_AMT_PAYMENT_MIN",
649
+ "INSTAL_AMT_PAYMENT_MAX",
650
+ "INSTAL_AMT_PAYMENT_MEAN",
651
+ "INSTAL_AMT_PAYMENT_SUM",
652
+ "INSTAL_DAYS_ENTRY_PAYMENT_MAX",
653
+ "INSTAL_DAYS_ENTRY_PAYMENT_MEAN",
654
+ "INSTAL_DAYS_ENTRY_PAYMENT_SUM",
655
+ "INSTAL_COUNT",
656
+ "CC_SK_ID_CURR_MIN",
657
+ "CC_SK_ID_CURR_MAX",
658
+ "CC_SK_ID_CURR_MEAN",
659
+ "CC_SK_ID_CURR_SUM",
660
+ "CC_SK_ID_CURR_VAR",
661
+ "CC_MONTHS_BALANCE_MIN",
662
+ "CC_MONTHS_BALANCE_MAX",
663
+ "CC_MONTHS_BALANCE_MEAN",
664
+ "CC_MONTHS_BALANCE_SUM",
665
+ "CC_MONTHS_BALANCE_VAR",
666
+ "CC_AMT_BALANCE_MIN",
667
+ "CC_AMT_BALANCE_MAX",
668
+ "CC_AMT_BALANCE_MEAN",
669
+ "CC_AMT_BALANCE_SUM",
670
+ "CC_AMT_BALANCE_VAR",
671
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_MIN",
672
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_MAX",
673
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_MEAN",
674
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_SUM",
675
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_VAR",
676
+ "CC_AMT_DRAWINGS_ATM_CURRENT_MIN",
677
+ "CC_AMT_DRAWINGS_ATM_CURRENT_MAX",
678
+ "CC_AMT_DRAWINGS_ATM_CURRENT_MEAN",
679
+ "CC_AMT_DRAWINGS_ATM_CURRENT_SUM",
680
+ "CC_AMT_DRAWINGS_ATM_CURRENT_VAR",
681
+ "CC_AMT_DRAWINGS_CURRENT_MIN",
682
+ "CC_AMT_DRAWINGS_CURRENT_MAX",
683
+ "CC_AMT_DRAWINGS_CURRENT_MEAN",
684
+ "CC_AMT_DRAWINGS_CURRENT_SUM",
685
+ "CC_AMT_DRAWINGS_CURRENT_VAR",
686
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_MIN",
687
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_MAX",
688
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_MEAN",
689
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_SUM",
690
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_VAR",
691
+ "CC_AMT_DRAWINGS_POS_CURRENT_MIN",
692
+ "CC_AMT_DRAWINGS_POS_CURRENT_MAX",
693
+ "CC_AMT_DRAWINGS_POS_CURRENT_MEAN",
694
+ "CC_AMT_DRAWINGS_POS_CURRENT_SUM",
695
+ "CC_AMT_DRAWINGS_POS_CURRENT_VAR",
696
+ "CC_AMT_INST_MIN_REGULARITY_MIN",
697
+ "CC_AMT_INST_MIN_REGULARITY_MAX",
698
+ "CC_AMT_INST_MIN_REGULARITY_MEAN",
699
+ "CC_AMT_INST_MIN_REGULARITY_SUM",
700
+ "CC_AMT_INST_MIN_REGULARITY_VAR",
701
+ "CC_AMT_PAYMENT_CURRENT_MIN",
702
+ "CC_AMT_PAYMENT_CURRENT_MAX",
703
+ "CC_AMT_PAYMENT_CURRENT_MEAN",
704
+ "CC_AMT_PAYMENT_CURRENT_SUM",
705
+ "CC_AMT_PAYMENT_CURRENT_VAR",
706
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_MIN",
707
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_MAX",
708
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_MEAN",
709
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_SUM",
710
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_VAR",
711
+ "CC_AMT_RECEIVABLE_PRINCIPAL_MIN",
712
+ "CC_AMT_RECEIVABLE_PRINCIPAL_MAX",
713
+ "CC_AMT_RECEIVABLE_PRINCIPAL_MEAN",
714
+ "CC_AMT_RECEIVABLE_PRINCIPAL_SUM",
715
+ "CC_AMT_RECEIVABLE_PRINCIPAL_VAR",
716
+ "CC_AMT_RECIVABLE_MIN",
717
+ "CC_AMT_RECIVABLE_MAX",
718
+ "CC_AMT_RECIVABLE_MEAN",
719
+ "CC_AMT_RECIVABLE_SUM",
720
+ "CC_AMT_RECIVABLE_VAR",
721
+ "CC_AMT_TOTAL_RECEIVABLE_MIN",
722
+ "CC_AMT_TOTAL_RECEIVABLE_MAX",
723
+ "CC_AMT_TOTAL_RECEIVABLE_MEAN",
724
+ "CC_AMT_TOTAL_RECEIVABLE_SUM",
725
+ "CC_AMT_TOTAL_RECEIVABLE_VAR",
726
+ "CC_CNT_DRAWINGS_ATM_CURRENT_MIN",
727
+ "CC_CNT_DRAWINGS_ATM_CURRENT_MAX",
728
+ "CC_CNT_DRAWINGS_ATM_CURRENT_MEAN",
729
+ "CC_CNT_DRAWINGS_ATM_CURRENT_SUM",
730
+ "CC_CNT_DRAWINGS_ATM_CURRENT_VAR",
731
+ "CC_CNT_DRAWINGS_CURRENT_MIN",
732
+ "CC_CNT_DRAWINGS_CURRENT_MAX",
733
+ "CC_CNT_DRAWINGS_CURRENT_MEAN",
734
+ "CC_CNT_DRAWINGS_CURRENT_SUM",
735
+ "CC_CNT_DRAWINGS_CURRENT_VAR",
736
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_MIN",
737
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_MAX",
738
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_MEAN",
739
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_SUM",
740
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_VAR",
741
+ "CC_CNT_DRAWINGS_POS_CURRENT_MIN",
742
+ "CC_CNT_DRAWINGS_POS_CURRENT_MAX",
743
+ "CC_CNT_DRAWINGS_POS_CURRENT_MEAN",
744
+ "CC_CNT_DRAWINGS_POS_CURRENT_SUM",
745
+ "CC_CNT_DRAWINGS_POS_CURRENT_VAR",
746
+ "CC_CNT_INSTALMENT_MATURE_CUM_MIN",
747
+ "CC_CNT_INSTALMENT_MATURE_CUM_MAX",
748
+ "CC_CNT_INSTALMENT_MATURE_CUM_MEAN",
749
+ "CC_CNT_INSTALMENT_MATURE_CUM_SUM",
750
+ "CC_CNT_INSTALMENT_MATURE_CUM_VAR",
751
+ "CC_SK_DPD_MIN",
752
+ "CC_SK_DPD_MAX",
753
+ "CC_SK_DPD_MEAN",
754
+ "CC_SK_DPD_SUM",
755
+ "CC_SK_DPD_VAR",
756
+ "CC_SK_DPD_DEF_MIN",
757
+ "CC_SK_DPD_DEF_MAX",
758
+ "CC_SK_DPD_DEF_MEAN",
759
+ "CC_SK_DPD_DEF_SUM",
760
+ "CC_SK_DPD_DEF_VAR",
761
+ "CC_NAME_CONTRACT_STATUS_Active_MEAN",
762
+ "CC_NAME_CONTRACT_STATUS_Approved_MEAN",
763
+ "CC_NAME_CONTRACT_STATUS_Completed_MEAN",
764
+ "CC_NAME_CONTRACT_STATUS_Demand_MEAN",
765
+ "CC_NAME_CONTRACT_STATUS_Refused_MEAN",
766
+ "CC_NAME_CONTRACT_STATUS_Sent proposal_MEAN",
767
+ "CC_NAME_CONTRACT_STATUS_Signed_MEAN",
768
+ "CC_NAME_CONTRACT_STATUS_nan_MEAN",
769
+ "CC_COUNT"
770
+ ]
models/model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0667c0a84722ad2728a709005707cbf67c1eeea4f1354bf584e39e9300bd5c89
3
+ size 22070483
models/model_info.json ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "lgbm_credit_scoring",
3
+ "version": "2",
4
+ "model_source": "models:/m-dbe6fc95d74c49a8bb4775a6b7516fcd",
5
+ "run_id": "b298ae7fcceb49118aa342716d79bb95",
6
+ "physical_path": "C:\\Users\\Kevin\\projects\\OC_P6\\mlartifacts\\3\\models\\m-dbe6fc95d74c49a8bb4775a6b7516fcd\\artifacts",
7
+ "exported_at": "2026-05-07T10:35:33.211492",
8
+ "metrics": {
9
+ "roc_auc_mean": 0.79,
10
+ "roc_auc_std": 0.0,
11
+ "pr_auc_mean": 0.28,
12
+ "pr_auc_std": 0.01,
13
+ "recall_mean": 0.68,
14
+ "recall_std": 0.04,
15
+ "precision_mean": 0.2,
16
+ "precision_std": 0.01,
17
+ "f1_mean": 0.3,
18
+ "f1_std": 0.01,
19
+ "fbeta_mean": 0.39,
20
+ "fbeta_std": 0.0,
21
+ "cost_mean": 23868.6,
22
+ "cost_std": 355.56,
23
+ "best_threshold_mean": 0.33,
24
+ "best_threshold_std": 0.03,
25
+ "test_roc_auc": 0.79,
26
+ "test_pr_auc": 0.28,
27
+ "test_recall": 0.71,
28
+ "test_precision": 0.18,
29
+ "test_f1": 0.29,
30
+ "test_fbeta": 0.38,
31
+ "test_cost": 29678.0
32
+ },
33
+ "params": {
34
+ "boosting_type": "gbdt",
35
+ "class_weight": "None",
36
+ "colsample_bytree": "0.801671563583984",
37
+ "importance_type": "split",
38
+ "learning_rate": "0.014287211983292707",
39
+ "max_depth": "-1",
40
+ "min_child_samples": "83",
41
+ "min_child_weight": "0.001",
42
+ "min_split_gain": "0.0",
43
+ "n_estimators": "773",
44
+ "n_jobs": "-1",
45
+ "num_leaves": "264",
46
+ "objective": "None",
47
+ "random_state": "42",
48
+ "reg_alpha": "6.930743941723339",
49
+ "reg_lambda": "0.4661687471215537",
50
+ "subsample": "0.8771054210270014",
51
+ "subsample_for_bin": "200000",
52
+ "subsample_freq": "0",
53
+ "model_name": "lgbm_optuna_best_full",
54
+ "sample_weight": "balanced",
55
+ "optimize_threshold": "True",
56
+ "n_trials": "100"
57
+ },
58
+ "n_features_expected": null,
59
+ "feature_names": null
60
+ }
models/no_history_template.json ADDED
@@ -0,0 +1,525 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "BURO_DAYS_CREDIT_MIN": null,
3
+ "BURO_DAYS_CREDIT_MAX": null,
4
+ "BURO_DAYS_CREDIT_MEAN": null,
5
+ "BURO_DAYS_CREDIT_VAR": null,
6
+ "BURO_DAYS_CREDIT_ENDDATE_MIN": null,
7
+ "BURO_DAYS_CREDIT_ENDDATE_MAX": null,
8
+ "BURO_DAYS_CREDIT_ENDDATE_MEAN": null,
9
+ "BURO_DAYS_CREDIT_UPDATE_MEAN": null,
10
+ "BURO_CREDIT_DAY_OVERDUE_MAX": null,
11
+ "BURO_CREDIT_DAY_OVERDUE_MEAN": null,
12
+ "BURO_AMT_CREDIT_MAX_OVERDUE_MEAN": null,
13
+ "BURO_AMT_CREDIT_SUM_MAX": null,
14
+ "BURO_AMT_CREDIT_SUM_MEAN": null,
15
+ "BURO_AMT_CREDIT_SUM_SUM": null,
16
+ "BURO_AMT_CREDIT_SUM_DEBT_MAX": null,
17
+ "BURO_AMT_CREDIT_SUM_DEBT_MEAN": null,
18
+ "BURO_AMT_CREDIT_SUM_DEBT_SUM": null,
19
+ "BURO_AMT_CREDIT_SUM_OVERDUE_MEAN": null,
20
+ "BURO_AMT_CREDIT_SUM_LIMIT_MEAN": null,
21
+ "BURO_AMT_CREDIT_SUM_LIMIT_SUM": null,
22
+ "BURO_AMT_ANNUITY_MAX": null,
23
+ "BURO_AMT_ANNUITY_MEAN": null,
24
+ "BURO_CNT_CREDIT_PROLONG_SUM": null,
25
+ "BURO_MONTHS_BALANCE_MIN_MIN": null,
26
+ "BURO_MONTHS_BALANCE_MAX_MAX": null,
27
+ "BURO_MONTHS_BALANCE_SIZE_MEAN": null,
28
+ "BURO_MONTHS_BALANCE_SIZE_SUM": null,
29
+ "BURO_CREDIT_ACTIVE_Active_MEAN": null,
30
+ "BURO_CREDIT_ACTIVE_Bad debt_MEAN": null,
31
+ "BURO_CREDIT_ACTIVE_Closed_MEAN": null,
32
+ "BURO_CREDIT_ACTIVE_Sold_MEAN": null,
33
+ "BURO_CREDIT_ACTIVE_nan_MEAN": null,
34
+ "BURO_CREDIT_CURRENCY_currency 1_MEAN": null,
35
+ "BURO_CREDIT_CURRENCY_currency 2_MEAN": null,
36
+ "BURO_CREDIT_CURRENCY_currency 3_MEAN": null,
37
+ "BURO_CREDIT_CURRENCY_currency 4_MEAN": null,
38
+ "BURO_CREDIT_CURRENCY_nan_MEAN": null,
39
+ "BURO_CREDIT_TYPE_Another type of loan_MEAN": null,
40
+ "BURO_CREDIT_TYPE_Car loan_MEAN": null,
41
+ "BURO_CREDIT_TYPE_Cash loan (non-earmarked)_MEAN": null,
42
+ "BURO_CREDIT_TYPE_Consumer credit_MEAN": null,
43
+ "BURO_CREDIT_TYPE_Credit card_MEAN": null,
44
+ "BURO_CREDIT_TYPE_Interbank credit_MEAN": null,
45
+ "BURO_CREDIT_TYPE_Loan for business development_MEAN": null,
46
+ "BURO_CREDIT_TYPE_Loan for purchase of shares (margin lending)_MEAN": null,
47
+ "BURO_CREDIT_TYPE_Loan for the purchase of equipment_MEAN": null,
48
+ "BURO_CREDIT_TYPE_Loan for working capital replenishment_MEAN": null,
49
+ "BURO_CREDIT_TYPE_Microloan_MEAN": null,
50
+ "BURO_CREDIT_TYPE_Mobile operator loan_MEAN": null,
51
+ "BURO_CREDIT_TYPE_Mortgage_MEAN": null,
52
+ "BURO_CREDIT_TYPE_Real estate loan_MEAN": null,
53
+ "BURO_CREDIT_TYPE_Unknown type of loan_MEAN": null,
54
+ "BURO_CREDIT_TYPE_nan_MEAN": null,
55
+ "BURO_STATUS_0_MEAN_MEAN": null,
56
+ "BURO_STATUS_1_MEAN_MEAN": null,
57
+ "BURO_STATUS_2_MEAN_MEAN": null,
58
+ "BURO_STATUS_3_MEAN_MEAN": null,
59
+ "BURO_STATUS_4_MEAN_MEAN": null,
60
+ "BURO_STATUS_5_MEAN_MEAN": null,
61
+ "BURO_STATUS_C_MEAN_MEAN": null,
62
+ "BURO_STATUS_X_MEAN_MEAN": null,
63
+ "BURO_STATUS_nan_MEAN_MEAN": null,
64
+ "ACTIVE_DAYS_CREDIT_MIN": null,
65
+ "ACTIVE_DAYS_CREDIT_MAX": null,
66
+ "ACTIVE_DAYS_CREDIT_MEAN": null,
67
+ "ACTIVE_DAYS_CREDIT_VAR": null,
68
+ "ACTIVE_DAYS_CREDIT_ENDDATE_MIN": null,
69
+ "ACTIVE_DAYS_CREDIT_ENDDATE_MAX": null,
70
+ "ACTIVE_DAYS_CREDIT_ENDDATE_MEAN": null,
71
+ "ACTIVE_DAYS_CREDIT_UPDATE_MEAN": null,
72
+ "ACTIVE_CREDIT_DAY_OVERDUE_MAX": null,
73
+ "ACTIVE_CREDIT_DAY_OVERDUE_MEAN": null,
74
+ "ACTIVE_AMT_CREDIT_MAX_OVERDUE_MEAN": null,
75
+ "ACTIVE_AMT_CREDIT_SUM_MAX": null,
76
+ "ACTIVE_AMT_CREDIT_SUM_MEAN": null,
77
+ "ACTIVE_AMT_CREDIT_SUM_SUM": null,
78
+ "ACTIVE_AMT_CREDIT_SUM_DEBT_MAX": null,
79
+ "ACTIVE_AMT_CREDIT_SUM_DEBT_MEAN": null,
80
+ "ACTIVE_AMT_CREDIT_SUM_DEBT_SUM": null,
81
+ "ACTIVE_AMT_CREDIT_SUM_OVERDUE_MEAN": null,
82
+ "ACTIVE_AMT_CREDIT_SUM_LIMIT_MEAN": null,
83
+ "ACTIVE_AMT_CREDIT_SUM_LIMIT_SUM": null,
84
+ "ACTIVE_AMT_ANNUITY_MAX": null,
85
+ "ACTIVE_AMT_ANNUITY_MEAN": null,
86
+ "ACTIVE_CNT_CREDIT_PROLONG_SUM": null,
87
+ "ACTIVE_MONTHS_BALANCE_MIN_MIN": null,
88
+ "ACTIVE_MONTHS_BALANCE_MAX_MAX": null,
89
+ "ACTIVE_MONTHS_BALANCE_SIZE_MEAN": null,
90
+ "ACTIVE_MONTHS_BALANCE_SIZE_SUM": null,
91
+ "CLOSED_DAYS_CREDIT_MIN": null,
92
+ "CLOSED_DAYS_CREDIT_MAX": null,
93
+ "CLOSED_DAYS_CREDIT_MEAN": null,
94
+ "CLOSED_DAYS_CREDIT_VAR": null,
95
+ "CLOSED_DAYS_CREDIT_ENDDATE_MIN": null,
96
+ "CLOSED_DAYS_CREDIT_ENDDATE_MAX": null,
97
+ "CLOSED_DAYS_CREDIT_ENDDATE_MEAN": null,
98
+ "CLOSED_DAYS_CREDIT_UPDATE_MEAN": null,
99
+ "CLOSED_CREDIT_DAY_OVERDUE_MAX": null,
100
+ "CLOSED_CREDIT_DAY_OVERDUE_MEAN": null,
101
+ "CLOSED_AMT_CREDIT_MAX_OVERDUE_MEAN": null,
102
+ "CLOSED_AMT_CREDIT_SUM_MAX": null,
103
+ "CLOSED_AMT_CREDIT_SUM_MEAN": null,
104
+ "CLOSED_AMT_CREDIT_SUM_SUM": null,
105
+ "CLOSED_AMT_CREDIT_SUM_DEBT_MAX": null,
106
+ "CLOSED_AMT_CREDIT_SUM_DEBT_MEAN": null,
107
+ "CLOSED_AMT_CREDIT_SUM_DEBT_SUM": null,
108
+ "CLOSED_AMT_CREDIT_SUM_OVERDUE_MEAN": null,
109
+ "CLOSED_AMT_CREDIT_SUM_LIMIT_MEAN": null,
110
+ "CLOSED_AMT_CREDIT_SUM_LIMIT_SUM": null,
111
+ "CLOSED_AMT_ANNUITY_MAX": null,
112
+ "CLOSED_AMT_ANNUITY_MEAN": null,
113
+ "CLOSED_CNT_CREDIT_PROLONG_SUM": null,
114
+ "CLOSED_MONTHS_BALANCE_MIN_MIN": null,
115
+ "CLOSED_MONTHS_BALANCE_MAX_MAX": null,
116
+ "CLOSED_MONTHS_BALANCE_SIZE_MEAN": null,
117
+ "CLOSED_MONTHS_BALANCE_SIZE_SUM": null,
118
+ "PREV_AMT_ANNUITY_MIN": null,
119
+ "PREV_AMT_ANNUITY_MAX": null,
120
+ "PREV_AMT_ANNUITY_MEAN": null,
121
+ "PREV_AMT_APPLICATION_MIN": null,
122
+ "PREV_AMT_APPLICATION_MAX": null,
123
+ "PREV_AMT_APPLICATION_MEAN": null,
124
+ "PREV_AMT_CREDIT_MIN": null,
125
+ "PREV_AMT_CREDIT_MAX": null,
126
+ "PREV_AMT_CREDIT_MEAN": null,
127
+ "PREV_APP_CREDIT_PERC_MIN": null,
128
+ "PREV_APP_CREDIT_PERC_MAX": null,
129
+ "PREV_APP_CREDIT_PERC_MEAN": null,
130
+ "PREV_APP_CREDIT_PERC_VAR": null,
131
+ "PREV_AMT_DOWN_PAYMENT_MIN": null,
132
+ "PREV_AMT_DOWN_PAYMENT_MAX": null,
133
+ "PREV_AMT_DOWN_PAYMENT_MEAN": null,
134
+ "PREV_AMT_GOODS_PRICE_MIN": null,
135
+ "PREV_AMT_GOODS_PRICE_MAX": null,
136
+ "PREV_AMT_GOODS_PRICE_MEAN": null,
137
+ "PREV_HOUR_APPR_PROCESS_START_MIN": null,
138
+ "PREV_HOUR_APPR_PROCESS_START_MAX": null,
139
+ "PREV_HOUR_APPR_PROCESS_START_MEAN": null,
140
+ "PREV_RATE_DOWN_PAYMENT_MIN": null,
141
+ "PREV_RATE_DOWN_PAYMENT_MAX": null,
142
+ "PREV_RATE_DOWN_PAYMENT_MEAN": null,
143
+ "PREV_DAYS_DECISION_MIN": null,
144
+ "PREV_DAYS_DECISION_MAX": null,
145
+ "PREV_DAYS_DECISION_MEAN": null,
146
+ "PREV_CNT_PAYMENT_MEAN": null,
147
+ "PREV_CNT_PAYMENT_SUM": null,
148
+ "PREV_NAME_CONTRACT_TYPE_Cash loans_MEAN": null,
149
+ "PREV_NAME_CONTRACT_TYPE_Consumer loans_MEAN": null,
150
+ "PREV_NAME_CONTRACT_TYPE_Revolving loans_MEAN": null,
151
+ "PREV_NAME_CONTRACT_TYPE_XNA_MEAN": null,
152
+ "PREV_NAME_CONTRACT_TYPE_nan_MEAN": null,
153
+ "PREV_WEEKDAY_APPR_PROCESS_START_FRIDAY_MEAN": null,
154
+ "PREV_WEEKDAY_APPR_PROCESS_START_MONDAY_MEAN": null,
155
+ "PREV_WEEKDAY_APPR_PROCESS_START_SATURDAY_MEAN": null,
156
+ "PREV_WEEKDAY_APPR_PROCESS_START_SUNDAY_MEAN": null,
157
+ "PREV_WEEKDAY_APPR_PROCESS_START_THURSDAY_MEAN": null,
158
+ "PREV_WEEKDAY_APPR_PROCESS_START_TUESDAY_MEAN": null,
159
+ "PREV_WEEKDAY_APPR_PROCESS_START_WEDNESDAY_MEAN": null,
160
+ "PREV_WEEKDAY_APPR_PROCESS_START_nan_MEAN": null,
161
+ "PREV_FLAG_LAST_APPL_PER_CONTRACT_N_MEAN": null,
162
+ "PREV_FLAG_LAST_APPL_PER_CONTRACT_Y_MEAN": null,
163
+ "PREV_FLAG_LAST_APPL_PER_CONTRACT_nan_MEAN": null,
164
+ "PREV_NAME_CASH_LOAN_PURPOSE_Building a house or an annex_MEAN": null,
165
+ "PREV_NAME_CASH_LOAN_PURPOSE_Business development_MEAN": null,
166
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a garage_MEAN": null,
167
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a holiday home / land_MEAN": null,
168
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a home_MEAN": null,
169
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a new car_MEAN": null,
170
+ "PREV_NAME_CASH_LOAN_PURPOSE_Buying a used car_MEAN": null,
171
+ "PREV_NAME_CASH_LOAN_PURPOSE_Car repairs_MEAN": null,
172
+ "PREV_NAME_CASH_LOAN_PURPOSE_Education_MEAN": null,
173
+ "PREV_NAME_CASH_LOAN_PURPOSE_Everyday expenses_MEAN": null,
174
+ "PREV_NAME_CASH_LOAN_PURPOSE_Furniture_MEAN": null,
175
+ "PREV_NAME_CASH_LOAN_PURPOSE_Gasification / water supply_MEAN": null,
176
+ "PREV_NAME_CASH_LOAN_PURPOSE_Hobby_MEAN": null,
177
+ "PREV_NAME_CASH_LOAN_PURPOSE_Journey_MEAN": null,
178
+ "PREV_NAME_CASH_LOAN_PURPOSE_Medicine_MEAN": null,
179
+ "PREV_NAME_CASH_LOAN_PURPOSE_Money for a third person_MEAN": null,
180
+ "PREV_NAME_CASH_LOAN_PURPOSE_Other_MEAN": null,
181
+ "PREV_NAME_CASH_LOAN_PURPOSE_Payments on other loans_MEAN": null,
182
+ "PREV_NAME_CASH_LOAN_PURPOSE_Purchase of electronic equipment_MEAN": null,
183
+ "PREV_NAME_CASH_LOAN_PURPOSE_Refusal to name the goal_MEAN": null,
184
+ "PREV_NAME_CASH_LOAN_PURPOSE_Repairs_MEAN": null,
185
+ "PREV_NAME_CASH_LOAN_PURPOSE_Urgent needs_MEAN": null,
186
+ "PREV_NAME_CASH_LOAN_PURPOSE_Wedding / gift / holiday_MEAN": null,
187
+ "PREV_NAME_CASH_LOAN_PURPOSE_XAP_MEAN": null,
188
+ "PREV_NAME_CASH_LOAN_PURPOSE_XNA_MEAN": null,
189
+ "PREV_NAME_CASH_LOAN_PURPOSE_nan_MEAN": null,
190
+ "PREV_NAME_CONTRACT_STATUS_Approved_MEAN": null,
191
+ "PREV_NAME_CONTRACT_STATUS_Canceled_MEAN": null,
192
+ "PREV_NAME_CONTRACT_STATUS_Refused_MEAN": null,
193
+ "PREV_NAME_CONTRACT_STATUS_Unused offer_MEAN": null,
194
+ "PREV_NAME_CONTRACT_STATUS_nan_MEAN": null,
195
+ "PREV_NAME_PAYMENT_TYPE_Cash through the bank_MEAN": null,
196
+ "PREV_NAME_PAYMENT_TYPE_Cashless from the account of the employer_MEAN": null,
197
+ "PREV_NAME_PAYMENT_TYPE_Non-cash from your account_MEAN": null,
198
+ "PREV_NAME_PAYMENT_TYPE_XNA_MEAN": null,
199
+ "PREV_NAME_PAYMENT_TYPE_nan_MEAN": null,
200
+ "PREV_CODE_REJECT_REASON_CLIENT_MEAN": null,
201
+ "PREV_CODE_REJECT_REASON_HC_MEAN": null,
202
+ "PREV_CODE_REJECT_REASON_LIMIT_MEAN": null,
203
+ "PREV_CODE_REJECT_REASON_SCO_MEAN": null,
204
+ "PREV_CODE_REJECT_REASON_SCOFR_MEAN": null,
205
+ "PREV_CODE_REJECT_REASON_SYSTEM_MEAN": null,
206
+ "PREV_CODE_REJECT_REASON_VERIF_MEAN": null,
207
+ "PREV_CODE_REJECT_REASON_XAP_MEAN": null,
208
+ "PREV_CODE_REJECT_REASON_XNA_MEAN": null,
209
+ "PREV_CODE_REJECT_REASON_nan_MEAN": null,
210
+ "PREV_NAME_TYPE_SUITE_Children_MEAN": null,
211
+ "PREV_NAME_TYPE_SUITE_Family_MEAN": null,
212
+ "PREV_NAME_TYPE_SUITE_Group of people_MEAN": null,
213
+ "PREV_NAME_TYPE_SUITE_Other_A_MEAN": null,
214
+ "PREV_NAME_TYPE_SUITE_Other_B_MEAN": null,
215
+ "PREV_NAME_TYPE_SUITE_Spouse, partner_MEAN": null,
216
+ "PREV_NAME_TYPE_SUITE_Unaccompanied_MEAN": null,
217
+ "PREV_NAME_TYPE_SUITE_nan_MEAN": null,
218
+ "PREV_NAME_CLIENT_TYPE_New_MEAN": null,
219
+ "PREV_NAME_CLIENT_TYPE_Refreshed_MEAN": null,
220
+ "PREV_NAME_CLIENT_TYPE_Repeater_MEAN": null,
221
+ "PREV_NAME_CLIENT_TYPE_XNA_MEAN": null,
222
+ "PREV_NAME_CLIENT_TYPE_nan_MEAN": null,
223
+ "PREV_NAME_GOODS_CATEGORY_Additional Service_MEAN": null,
224
+ "PREV_NAME_GOODS_CATEGORY_Animals_MEAN": null,
225
+ "PREV_NAME_GOODS_CATEGORY_Audio/Video_MEAN": null,
226
+ "PREV_NAME_GOODS_CATEGORY_Auto Accessories_MEAN": null,
227
+ "PREV_NAME_GOODS_CATEGORY_Clothing and Accessories_MEAN": null,
228
+ "PREV_NAME_GOODS_CATEGORY_Computers_MEAN": null,
229
+ "PREV_NAME_GOODS_CATEGORY_Construction Materials_MEAN": null,
230
+ "PREV_NAME_GOODS_CATEGORY_Consumer Electronics_MEAN": null,
231
+ "PREV_NAME_GOODS_CATEGORY_Direct Sales_MEAN": null,
232
+ "PREV_NAME_GOODS_CATEGORY_Education_MEAN": null,
233
+ "PREV_NAME_GOODS_CATEGORY_Fitness_MEAN": null,
234
+ "PREV_NAME_GOODS_CATEGORY_Furniture_MEAN": null,
235
+ "PREV_NAME_GOODS_CATEGORY_Gardening_MEAN": null,
236
+ "PREV_NAME_GOODS_CATEGORY_Homewares_MEAN": null,
237
+ "PREV_NAME_GOODS_CATEGORY_House Construction_MEAN": null,
238
+ "PREV_NAME_GOODS_CATEGORY_Insurance_MEAN": null,
239
+ "PREV_NAME_GOODS_CATEGORY_Jewelry_MEAN": null,
240
+ "PREV_NAME_GOODS_CATEGORY_Medical Supplies_MEAN": null,
241
+ "PREV_NAME_GOODS_CATEGORY_Medicine_MEAN": null,
242
+ "PREV_NAME_GOODS_CATEGORY_Mobile_MEAN": null,
243
+ "PREV_NAME_GOODS_CATEGORY_Office Appliances_MEAN": null,
244
+ "PREV_NAME_GOODS_CATEGORY_Other_MEAN": null,
245
+ "PREV_NAME_GOODS_CATEGORY_Photo / Cinema Equipment_MEAN": null,
246
+ "PREV_NAME_GOODS_CATEGORY_Sport and Leisure_MEAN": null,
247
+ "PREV_NAME_GOODS_CATEGORY_Tourism_MEAN": null,
248
+ "PREV_NAME_GOODS_CATEGORY_Vehicles_MEAN": null,
249
+ "PREV_NAME_GOODS_CATEGORY_Weapon_MEAN": null,
250
+ "PREV_NAME_GOODS_CATEGORY_XNA_MEAN": null,
251
+ "PREV_NAME_GOODS_CATEGORY_nan_MEAN": null,
252
+ "PREV_NAME_PORTFOLIO_Cards_MEAN": null,
253
+ "PREV_NAME_PORTFOLIO_Cars_MEAN": null,
254
+ "PREV_NAME_PORTFOLIO_Cash_MEAN": null,
255
+ "PREV_NAME_PORTFOLIO_POS_MEAN": null,
256
+ "PREV_NAME_PORTFOLIO_XNA_MEAN": null,
257
+ "PREV_NAME_PORTFOLIO_nan_MEAN": null,
258
+ "PREV_NAME_PRODUCT_TYPE_XNA_MEAN": null,
259
+ "PREV_NAME_PRODUCT_TYPE_walk-in_MEAN": null,
260
+ "PREV_NAME_PRODUCT_TYPE_x-sell_MEAN": null,
261
+ "PREV_NAME_PRODUCT_TYPE_nan_MEAN": null,
262
+ "PREV_CHANNEL_TYPE_AP+ (Cash loan)_MEAN": null,
263
+ "PREV_CHANNEL_TYPE_Car dealer_MEAN": null,
264
+ "PREV_CHANNEL_TYPE_Channel of corporate sales_MEAN": null,
265
+ "PREV_CHANNEL_TYPE_Contact center_MEAN": null,
266
+ "PREV_CHANNEL_TYPE_Country-wide_MEAN": null,
267
+ "PREV_CHANNEL_TYPE_Credit and cash offices_MEAN": null,
268
+ "PREV_CHANNEL_TYPE_Regional / Local_MEAN": null,
269
+ "PREV_CHANNEL_TYPE_Stone_MEAN": null,
270
+ "PREV_CHANNEL_TYPE_nan_MEAN": null,
271
+ "PREV_NAME_SELLER_INDUSTRY_Auto technology_MEAN": null,
272
+ "PREV_NAME_SELLER_INDUSTRY_Clothing_MEAN": null,
273
+ "PREV_NAME_SELLER_INDUSTRY_Connectivity_MEAN": null,
274
+ "PREV_NAME_SELLER_INDUSTRY_Construction_MEAN": null,
275
+ "PREV_NAME_SELLER_INDUSTRY_Consumer electronics_MEAN": null,
276
+ "PREV_NAME_SELLER_INDUSTRY_Furniture_MEAN": null,
277
+ "PREV_NAME_SELLER_INDUSTRY_Industry_MEAN": null,
278
+ "PREV_NAME_SELLER_INDUSTRY_Jewelry_MEAN": null,
279
+ "PREV_NAME_SELLER_INDUSTRY_MLM partners_MEAN": null,
280
+ "PREV_NAME_SELLER_INDUSTRY_Tourism_MEAN": null,
281
+ "PREV_NAME_SELLER_INDUSTRY_XNA_MEAN": null,
282
+ "PREV_NAME_SELLER_INDUSTRY_nan_MEAN": null,
283
+ "PREV_NAME_YIELD_GROUP_XNA_MEAN": null,
284
+ "PREV_NAME_YIELD_GROUP_high_MEAN": null,
285
+ "PREV_NAME_YIELD_GROUP_low_action_MEAN": null,
286
+ "PREV_NAME_YIELD_GROUP_low_normal_MEAN": null,
287
+ "PREV_NAME_YIELD_GROUP_middle_MEAN": null,
288
+ "PREV_NAME_YIELD_GROUP_nan_MEAN": null,
289
+ "PREV_PRODUCT_COMBINATION_Card Street_MEAN": null,
290
+ "PREV_PRODUCT_COMBINATION_Card X-Sell_MEAN": null,
291
+ "PREV_PRODUCT_COMBINATION_Cash_MEAN": null,
292
+ "PREV_PRODUCT_COMBINATION_Cash Street: high_MEAN": null,
293
+ "PREV_PRODUCT_COMBINATION_Cash Street: low_MEAN": null,
294
+ "PREV_PRODUCT_COMBINATION_Cash Street: middle_MEAN": null,
295
+ "PREV_PRODUCT_COMBINATION_Cash X-Sell: high_MEAN": null,
296
+ "PREV_PRODUCT_COMBINATION_Cash X-Sell: low_MEAN": null,
297
+ "PREV_PRODUCT_COMBINATION_Cash X-Sell: middle_MEAN": null,
298
+ "PREV_PRODUCT_COMBINATION_POS household with interest_MEAN": null,
299
+ "PREV_PRODUCT_COMBINATION_POS household without interest_MEAN": null,
300
+ "PREV_PRODUCT_COMBINATION_POS industry with interest_MEAN": null,
301
+ "PREV_PRODUCT_COMBINATION_POS industry without interest_MEAN": null,
302
+ "PREV_PRODUCT_COMBINATION_POS mobile with interest_MEAN": null,
303
+ "PREV_PRODUCT_COMBINATION_POS mobile without interest_MEAN": null,
304
+ "PREV_PRODUCT_COMBINATION_POS other with interest_MEAN": null,
305
+ "PREV_PRODUCT_COMBINATION_POS others without interest_MEAN": null,
306
+ "PREV_PRODUCT_COMBINATION_nan_MEAN": null,
307
+ "APPROVED_AMT_ANNUITY_MIN": null,
308
+ "APPROVED_AMT_ANNUITY_MAX": null,
309
+ "APPROVED_AMT_ANNUITY_MEAN": null,
310
+ "APPROVED_AMT_APPLICATION_MIN": null,
311
+ "APPROVED_AMT_APPLICATION_MAX": null,
312
+ "APPROVED_AMT_APPLICATION_MEAN": null,
313
+ "APPROVED_AMT_CREDIT_MIN": null,
314
+ "APPROVED_AMT_CREDIT_MAX": null,
315
+ "APPROVED_AMT_CREDIT_MEAN": null,
316
+ "APPROVED_APP_CREDIT_PERC_MIN": null,
317
+ "APPROVED_APP_CREDIT_PERC_MAX": null,
318
+ "APPROVED_APP_CREDIT_PERC_MEAN": null,
319
+ "APPROVED_APP_CREDIT_PERC_VAR": null,
320
+ "APPROVED_AMT_DOWN_PAYMENT_MIN": null,
321
+ "APPROVED_AMT_DOWN_PAYMENT_MAX": null,
322
+ "APPROVED_AMT_DOWN_PAYMENT_MEAN": null,
323
+ "APPROVED_AMT_GOODS_PRICE_MIN": null,
324
+ "APPROVED_AMT_GOODS_PRICE_MAX": null,
325
+ "APPROVED_AMT_GOODS_PRICE_MEAN": null,
326
+ "APPROVED_HOUR_APPR_PROCESS_START_MIN": null,
327
+ "APPROVED_HOUR_APPR_PROCESS_START_MAX": null,
328
+ "APPROVED_HOUR_APPR_PROCESS_START_MEAN": null,
329
+ "APPROVED_RATE_DOWN_PAYMENT_MIN": null,
330
+ "APPROVED_RATE_DOWN_PAYMENT_MAX": null,
331
+ "APPROVED_RATE_DOWN_PAYMENT_MEAN": null,
332
+ "APPROVED_DAYS_DECISION_MIN": null,
333
+ "APPROVED_DAYS_DECISION_MAX": null,
334
+ "APPROVED_DAYS_DECISION_MEAN": null,
335
+ "APPROVED_CNT_PAYMENT_MEAN": null,
336
+ "APPROVED_CNT_PAYMENT_SUM": null,
337
+ "REFUSED_AMT_ANNUITY_MIN": null,
338
+ "REFUSED_AMT_ANNUITY_MAX": null,
339
+ "REFUSED_AMT_ANNUITY_MEAN": null,
340
+ "REFUSED_AMT_APPLICATION_MIN": null,
341
+ "REFUSED_AMT_APPLICATION_MAX": null,
342
+ "REFUSED_AMT_APPLICATION_MEAN": null,
343
+ "REFUSED_AMT_CREDIT_MIN": null,
344
+ "REFUSED_AMT_CREDIT_MAX": null,
345
+ "REFUSED_AMT_CREDIT_MEAN": null,
346
+ "REFUSED_APP_CREDIT_PERC_MIN": null,
347
+ "REFUSED_APP_CREDIT_PERC_MAX": null,
348
+ "REFUSED_APP_CREDIT_PERC_MEAN": null,
349
+ "REFUSED_APP_CREDIT_PERC_VAR": null,
350
+ "REFUSED_AMT_DOWN_PAYMENT_MIN": null,
351
+ "REFUSED_AMT_DOWN_PAYMENT_MAX": null,
352
+ "REFUSED_AMT_DOWN_PAYMENT_MEAN": null,
353
+ "REFUSED_AMT_GOODS_PRICE_MIN": null,
354
+ "REFUSED_AMT_GOODS_PRICE_MAX": null,
355
+ "REFUSED_AMT_GOODS_PRICE_MEAN": null,
356
+ "REFUSED_HOUR_APPR_PROCESS_START_MIN": null,
357
+ "REFUSED_HOUR_APPR_PROCESS_START_MAX": null,
358
+ "REFUSED_HOUR_APPR_PROCESS_START_MEAN": null,
359
+ "REFUSED_RATE_DOWN_PAYMENT_MIN": null,
360
+ "REFUSED_RATE_DOWN_PAYMENT_MAX": null,
361
+ "REFUSED_RATE_DOWN_PAYMENT_MEAN": null,
362
+ "REFUSED_DAYS_DECISION_MIN": null,
363
+ "REFUSED_DAYS_DECISION_MAX": null,
364
+ "REFUSED_DAYS_DECISION_MEAN": null,
365
+ "REFUSED_CNT_PAYMENT_MEAN": null,
366
+ "REFUSED_CNT_PAYMENT_SUM": null,
367
+ "POS_MONTHS_BALANCE_MAX": null,
368
+ "POS_MONTHS_BALANCE_MEAN": null,
369
+ "POS_MONTHS_BALANCE_SIZE": null,
370
+ "POS_SK_DPD_MAX": null,
371
+ "POS_SK_DPD_MEAN": null,
372
+ "POS_SK_DPD_DEF_MAX": null,
373
+ "POS_SK_DPD_DEF_MEAN": null,
374
+ "POS_NAME_CONTRACT_STATUS_Active_MEAN": null,
375
+ "POS_NAME_CONTRACT_STATUS_Amortized debt_MEAN": null,
376
+ "POS_NAME_CONTRACT_STATUS_Approved_MEAN": null,
377
+ "POS_NAME_CONTRACT_STATUS_Canceled_MEAN": null,
378
+ "POS_NAME_CONTRACT_STATUS_Completed_MEAN": null,
379
+ "POS_NAME_CONTRACT_STATUS_Demand_MEAN": null,
380
+ "POS_NAME_CONTRACT_STATUS_Returned to the store_MEAN": null,
381
+ "POS_NAME_CONTRACT_STATUS_Signed_MEAN": null,
382
+ "POS_NAME_CONTRACT_STATUS_XNA_MEAN": null,
383
+ "POS_NAME_CONTRACT_STATUS_nan_MEAN": null,
384
+ "POS_COUNT": 0,
385
+ "INSTAL_NUM_INSTALMENT_VERSION_NUNIQUE": null,
386
+ "INSTAL_DPD_MAX": null,
387
+ "INSTAL_DPD_MEAN": null,
388
+ "INSTAL_DPD_SUM": null,
389
+ "INSTAL_DBD_MAX": null,
390
+ "INSTAL_DBD_MEAN": null,
391
+ "INSTAL_DBD_SUM": null,
392
+ "INSTAL_PAYMENT_PERC_MAX": null,
393
+ "INSTAL_PAYMENT_PERC_MEAN": null,
394
+ "INSTAL_PAYMENT_PERC_SUM": null,
395
+ "INSTAL_PAYMENT_PERC_VAR": null,
396
+ "INSTAL_PAYMENT_DIFF_MAX": null,
397
+ "INSTAL_PAYMENT_DIFF_MEAN": null,
398
+ "INSTAL_PAYMENT_DIFF_SUM": null,
399
+ "INSTAL_PAYMENT_DIFF_VAR": null,
400
+ "INSTAL_AMT_INSTALMENT_MAX": null,
401
+ "INSTAL_AMT_INSTALMENT_MEAN": null,
402
+ "INSTAL_AMT_INSTALMENT_SUM": null,
403
+ "INSTAL_AMT_PAYMENT_MIN": null,
404
+ "INSTAL_AMT_PAYMENT_MAX": null,
405
+ "INSTAL_AMT_PAYMENT_MEAN": null,
406
+ "INSTAL_AMT_PAYMENT_SUM": null,
407
+ "INSTAL_DAYS_ENTRY_PAYMENT_MAX": null,
408
+ "INSTAL_DAYS_ENTRY_PAYMENT_MEAN": null,
409
+ "INSTAL_DAYS_ENTRY_PAYMENT_SUM": null,
410
+ "INSTAL_COUNT": 0,
411
+ "CC_SK_ID_CURR_MIN": null,
412
+ "CC_SK_ID_CURR_MAX": null,
413
+ "CC_SK_ID_CURR_MEAN": null,
414
+ "CC_SK_ID_CURR_SUM": null,
415
+ "CC_SK_ID_CURR_VAR": null,
416
+ "CC_MONTHS_BALANCE_MIN": null,
417
+ "CC_MONTHS_BALANCE_MAX": null,
418
+ "CC_MONTHS_BALANCE_MEAN": null,
419
+ "CC_MONTHS_BALANCE_SUM": null,
420
+ "CC_MONTHS_BALANCE_VAR": null,
421
+ "CC_AMT_BALANCE_MIN": null,
422
+ "CC_AMT_BALANCE_MAX": null,
423
+ "CC_AMT_BALANCE_MEAN": null,
424
+ "CC_AMT_BALANCE_SUM": null,
425
+ "CC_AMT_BALANCE_VAR": null,
426
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_MIN": null,
427
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_MAX": null,
428
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_MEAN": null,
429
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_SUM": null,
430
+ "CC_AMT_CREDIT_LIMIT_ACTUAL_VAR": null,
431
+ "CC_AMT_DRAWINGS_ATM_CURRENT_MIN": null,
432
+ "CC_AMT_DRAWINGS_ATM_CURRENT_MAX": null,
433
+ "CC_AMT_DRAWINGS_ATM_CURRENT_MEAN": null,
434
+ "CC_AMT_DRAWINGS_ATM_CURRENT_SUM": null,
435
+ "CC_AMT_DRAWINGS_ATM_CURRENT_VAR": null,
436
+ "CC_AMT_DRAWINGS_CURRENT_MIN": null,
437
+ "CC_AMT_DRAWINGS_CURRENT_MAX": null,
438
+ "CC_AMT_DRAWINGS_CURRENT_MEAN": null,
439
+ "CC_AMT_DRAWINGS_CURRENT_SUM": null,
440
+ "CC_AMT_DRAWINGS_CURRENT_VAR": null,
441
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_MIN": null,
442
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_MAX": null,
443
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_MEAN": null,
444
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_SUM": null,
445
+ "CC_AMT_DRAWINGS_OTHER_CURRENT_VAR": null,
446
+ "CC_AMT_DRAWINGS_POS_CURRENT_MIN": null,
447
+ "CC_AMT_DRAWINGS_POS_CURRENT_MAX": null,
448
+ "CC_AMT_DRAWINGS_POS_CURRENT_MEAN": null,
449
+ "CC_AMT_DRAWINGS_POS_CURRENT_SUM": null,
450
+ "CC_AMT_DRAWINGS_POS_CURRENT_VAR": null,
451
+ "CC_AMT_INST_MIN_REGULARITY_MIN": null,
452
+ "CC_AMT_INST_MIN_REGULARITY_MAX": null,
453
+ "CC_AMT_INST_MIN_REGULARITY_MEAN": null,
454
+ "CC_AMT_INST_MIN_REGULARITY_SUM": null,
455
+ "CC_AMT_INST_MIN_REGULARITY_VAR": null,
456
+ "CC_AMT_PAYMENT_CURRENT_MIN": null,
457
+ "CC_AMT_PAYMENT_CURRENT_MAX": null,
458
+ "CC_AMT_PAYMENT_CURRENT_MEAN": null,
459
+ "CC_AMT_PAYMENT_CURRENT_SUM": null,
460
+ "CC_AMT_PAYMENT_CURRENT_VAR": null,
461
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_MIN": null,
462
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_MAX": null,
463
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_MEAN": null,
464
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_SUM": null,
465
+ "CC_AMT_PAYMENT_TOTAL_CURRENT_VAR": null,
466
+ "CC_AMT_RECEIVABLE_PRINCIPAL_MIN": null,
467
+ "CC_AMT_RECEIVABLE_PRINCIPAL_MAX": null,
468
+ "CC_AMT_RECEIVABLE_PRINCIPAL_MEAN": null,
469
+ "CC_AMT_RECEIVABLE_PRINCIPAL_SUM": null,
470
+ "CC_AMT_RECEIVABLE_PRINCIPAL_VAR": null,
471
+ "CC_AMT_RECIVABLE_MIN": null,
472
+ "CC_AMT_RECIVABLE_MAX": null,
473
+ "CC_AMT_RECIVABLE_MEAN": null,
474
+ "CC_AMT_RECIVABLE_SUM": null,
475
+ "CC_AMT_RECIVABLE_VAR": null,
476
+ "CC_AMT_TOTAL_RECEIVABLE_MIN": null,
477
+ "CC_AMT_TOTAL_RECEIVABLE_MAX": null,
478
+ "CC_AMT_TOTAL_RECEIVABLE_MEAN": null,
479
+ "CC_AMT_TOTAL_RECEIVABLE_SUM": null,
480
+ "CC_AMT_TOTAL_RECEIVABLE_VAR": null,
481
+ "CC_CNT_DRAWINGS_ATM_CURRENT_MIN": null,
482
+ "CC_CNT_DRAWINGS_ATM_CURRENT_MAX": null,
483
+ "CC_CNT_DRAWINGS_ATM_CURRENT_MEAN": null,
484
+ "CC_CNT_DRAWINGS_ATM_CURRENT_SUM": null,
485
+ "CC_CNT_DRAWINGS_ATM_CURRENT_VAR": null,
486
+ "CC_CNT_DRAWINGS_CURRENT_MIN": null,
487
+ "CC_CNT_DRAWINGS_CURRENT_MAX": null,
488
+ "CC_CNT_DRAWINGS_CURRENT_MEAN": null,
489
+ "CC_CNT_DRAWINGS_CURRENT_SUM": null,
490
+ "CC_CNT_DRAWINGS_CURRENT_VAR": null,
491
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_MIN": null,
492
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_MAX": null,
493
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_MEAN": null,
494
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_SUM": null,
495
+ "CC_CNT_DRAWINGS_OTHER_CURRENT_VAR": null,
496
+ "CC_CNT_DRAWINGS_POS_CURRENT_MIN": null,
497
+ "CC_CNT_DRAWINGS_POS_CURRENT_MAX": null,
498
+ "CC_CNT_DRAWINGS_POS_CURRENT_MEAN": null,
499
+ "CC_CNT_DRAWINGS_POS_CURRENT_SUM": null,
500
+ "CC_CNT_DRAWINGS_POS_CURRENT_VAR": null,
501
+ "CC_CNT_INSTALMENT_MATURE_CUM_MIN": null,
502
+ "CC_CNT_INSTALMENT_MATURE_CUM_MAX": null,
503
+ "CC_CNT_INSTALMENT_MATURE_CUM_MEAN": null,
504
+ "CC_CNT_INSTALMENT_MATURE_CUM_SUM": null,
505
+ "CC_CNT_INSTALMENT_MATURE_CUM_VAR": null,
506
+ "CC_SK_DPD_MIN": null,
507
+ "CC_SK_DPD_MAX": null,
508
+ "CC_SK_DPD_MEAN": null,
509
+ "CC_SK_DPD_SUM": null,
510
+ "CC_SK_DPD_VAR": null,
511
+ "CC_SK_DPD_DEF_MIN": null,
512
+ "CC_SK_DPD_DEF_MAX": null,
513
+ "CC_SK_DPD_DEF_MEAN": null,
514
+ "CC_SK_DPD_DEF_SUM": null,
515
+ "CC_SK_DPD_DEF_VAR": null,
516
+ "CC_NAME_CONTRACT_STATUS_Active_MEAN": null,
517
+ "CC_NAME_CONTRACT_STATUS_Approved_MEAN": null,
518
+ "CC_NAME_CONTRACT_STATUS_Completed_MEAN": null,
519
+ "CC_NAME_CONTRACT_STATUS_Demand_MEAN": null,
520
+ "CC_NAME_CONTRACT_STATUS_Refused_MEAN": null,
521
+ "CC_NAME_CONTRACT_STATUS_Sent proposal_MEAN": null,
522
+ "CC_NAME_CONTRACT_STATUS_Signed_MEAN": null,
523
+ "CC_NAME_CONTRACT_STATUS_nan_MEAN": null,
524
+ "CC_COUNT": 0
525
+ }
notebook.ipynb ADDED
File without changes
notebooks/EDA.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
notebooks/Modelisation.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
notebooks/Optimisation.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "oc-p8"
3
+ version = "0.1.0"
4
+ description = "MLOps pipeline for credit scoring model from OC_P6"
5
+ requires-python = ">=3.12,<3.13"
6
+ dependencies = [
7
+ "fastapi>=0.136.1",
8
+ "ipykernel>=7.2.0",
9
+ "jupyter>=1.1.1",
10
+ "lightgbm>=4.0.0",
11
+ "matplotlib>=3.10.8",
12
+ "mlflow>=2.0.0",
13
+ "numpy>=2.4.3",
14
+ "optuna>=3.0.0",
15
+ "pandas==2.3.3",
16
+ "plotly>=5.0.0",
17
+ "pyarrow>=23.0.1",
18
+ "pydantic>=2.13.3",
19
+ "scikit-learn>=1.8.0",
20
+ "seaborn>=0.13.2",
21
+ "shap>=0.46.0,!=0.51.0",
22
+ "uvicorn[standard]>=0.46.0",
23
+ "xgboost>=2.0.0",
24
+ ]
25
+
26
+ [dependency-groups]
27
+ dev = [
28
+ "httpx>=0.28.1",
29
+ "pytest>=9.0.3",
30
+ "pytest-cov>=7.1.0",
31
+ "ruff>=0.15.12",
32
+ ]
scripts/build_feature_store.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Offline script: build the runtime feature store and metadata artefacts.
2
+
3
+ Outputs:
4
+ - data/features_store.parquet : ~600 aggregated columns indexed by SK_ID_CURR
5
+ (bureau / prev / POS / CC / install only —
6
+ application_train columns are reconstructed
7
+ at inference time from the JSON input).
8
+ - models/feature_names.json : ordered list of the 768 columns the model expects.
9
+ - models/app_train_columns.json : metadata for the 122 raw app_train columns
10
+ (dtype, min, max, sample) — used to draft the
11
+ Pydantic schema and validate inference inputs.
12
+ - models/app_train_categories.json : exhaustive list of categorical values seen in
13
+ training, per column. Crucial for one-hot
14
+ consistency at inference time.
15
+
16
+ Run once before starting the API:
17
+ uv run python scripts/build_feature_store.py
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import json
23
+ import sys
24
+ from pathlib import Path
25
+
26
+ import pandas as pd
27
+
28
+ # allow importing feature_engineering from the project root
29
+ ROOT = Path(__file__).resolve().parents[1]
30
+ sys.path.insert(0, str(ROOT))
31
+
32
+ from feature_engineering.aggregations import ( # noqa: E402
33
+ bureau_and_balance,
34
+ credit_card_balance,
35
+ installments_payments,
36
+ pos_cash,
37
+ previous_applications,
38
+ )
39
+ from feature_engineering.orchestrator import merge_files # noqa: E402
40
+
41
+ DATA_DIR = Path("C:/Users/Kevin/projects/OC_P6/data")
42
+ OUT_PARQUET = ROOT / "data" / "features_store.parquet"
43
+ OUT_FEATURE_NAMES = ROOT / "models" / "feature_names.json"
44
+ OUT_APP_TRAIN_COLS = ROOT / "models" / "app_train_columns.json"
45
+ OUT_APP_TRAIN_CATEGORIES = ROOT / "models" / "app_train_categories.json"
46
+ OUT_BINARY_MAPPINGS = ROOT / "models" / "app_train_binary_mappings.json"
47
+
48
+ # Same binary columns the notebook factorizes — order matters.
49
+ BINARY_COLUMNS = ["CODE_GENDER", "FLAG_OWN_CAR", "FLAG_OWN_REALTY"]
50
+
51
+
52
+ def _build_app_train_metadata(data_dir: Path) -> tuple[dict, dict, dict]:
53
+ """Read the raw application_train.csv and return:
54
+ - column_meta: {col: {dtype, min, max, n_missing, sample}}
55
+ - categories: {col: [unique values]} for object-dtype columns (excluding the
56
+ binary ones, since those are factorized rather than one-hot encoded)
57
+ - binary_mappings: {col: {value: code}} for the 3 binary columns, captured
58
+ with the EXACT same first-occurrence order pd.factorize() saw at training.
59
+ """
60
+ raw = pd.read_csv(data_dir / "application_train.csv")
61
+ raw = raw[raw["CODE_GENDER"] != "XNA"].reset_index(drop=True)
62
+
63
+ binary_mappings: dict[str, dict[str, int]] = {}
64
+ for col in BINARY_COLUMNS:
65
+ codes, uniques = pd.factorize(raw[col])
66
+ binary_mappings[col] = {str(v): int(i) for i, v in enumerate(uniques)}
67
+
68
+ column_meta: dict[str, dict] = {}
69
+ categories: dict[str, list] = {}
70
+
71
+ for col in raw.columns:
72
+ dtype = str(raw[col].dtype)
73
+ n_missing = int(raw[col].isna().sum())
74
+ meta: dict = {"dtype": dtype, "n_missing": n_missing}
75
+
76
+ if raw[col].dtype == "object":
77
+ uniques_sorted = sorted(raw[col].dropna().unique().tolist())
78
+ meta["categories"] = uniques_sorted
79
+ if col not in BINARY_COLUMNS:
80
+ categories[col] = uniques_sorted
81
+ else:
82
+ non_null = raw[col].dropna()
83
+ if len(non_null) > 0:
84
+ meta["min"] = float(non_null.min())
85
+ meta["max"] = float(non_null.max())
86
+ meta["sample"] = float(non_null.iloc[0])
87
+ column_meta[col] = meta
88
+
89
+ return column_meta, categories, binary_mappings
90
+
91
+
92
+ def _build_aggregate_only_store(data_dir: Path) -> pd.DataFrame:
93
+ """Build the parquet that contains ONLY the auxiliary aggregates.
94
+
95
+ application_train columns are deliberately excluded — they are always
96
+ reconstructed at inference time from the JSON input.
97
+ """
98
+ bureau = bureau_and_balance(data_dir)
99
+ print(f" bureau aggregates: {bureau.shape}")
100
+
101
+ prev = previous_applications(data_dir)
102
+ print(f" previous_application aggregates: {prev.shape}")
103
+
104
+ pos = pos_cash(data_dir)
105
+ print(f" POS_CASH aggregates: {pos.shape}")
106
+
107
+ ins = installments_payments(data_dir)
108
+ print(f" installments aggregates: {ins.shape}")
109
+
110
+ cc = credit_card_balance(data_dir)
111
+ print(f" credit_card aggregates: {cc.shape}")
112
+
113
+ # Outer-join all aggregates on SK_ID_CURR. Any client absent from a given
114
+ # auxiliary file will simply have NaN there — preserves the training signal.
115
+ out = bureau.join(prev, how="outer").join(pos, how="outer")
116
+ out = out.join(ins, how="outer").join(cc, how="outer")
117
+ return out
118
+
119
+
120
+ def _extract_feature_names_from_full_pipeline(data_dir: Path) -> list[str]:
121
+ """Run the full merge_files() once to recover the exact 770-column order
122
+ the model was trained on. We keep only the 768 feature columns
123
+ (excluding SK_ID_CURR and TARGET)."""
124
+ print("Building full training dataframe to capture feature_names...")
125
+ df = merge_files(data_dir)
126
+ feature_cols = [c for c in df.columns if c not in ("SK_ID_CURR", "TARGET")]
127
+ return feature_cols
128
+
129
+
130
+ def main() -> None:
131
+ OUT_PARQUET.parent.mkdir(parents=True, exist_ok=True)
132
+ OUT_FEATURE_NAMES.parent.mkdir(parents=True, exist_ok=True)
133
+
134
+ print("=" * 70)
135
+ print("STEP 1 — extracting raw application_train metadata")
136
+ column_meta, categories, binary_mappings = _build_app_train_metadata(DATA_DIR)
137
+ print(f" {len(column_meta)} columns analysed, {len(categories)} multi-cat")
138
+ print(f" binary mappings: {binary_mappings}")
139
+
140
+ print("\nSTEP 2 — building aggregate-only feature store")
141
+ agg_store = _build_aggregate_only_store(DATA_DIR)
142
+ print(f" Combined aggregates: {agg_store.shape}")
143
+
144
+ print("\nSTEP 3 — extracting feature_names from full training pipeline")
145
+ feature_names = _extract_feature_names_from_full_pipeline(DATA_DIR)
146
+ print(f" {len(feature_names)} feature columns identified")
147
+
148
+ print("\nSTEP 4 — persisting artefacts")
149
+ agg_store.to_parquet(OUT_PARQUET, compression="snappy")
150
+ size_mb = OUT_PARQUET.stat().st_size / 1e6
151
+ print(f" ✅ {OUT_PARQUET} ({size_mb:.1f} MB)")
152
+
153
+ OUT_FEATURE_NAMES.write_text(json.dumps(feature_names, indent=2))
154
+ print(f" ✅ {OUT_FEATURE_NAMES}")
155
+
156
+ OUT_APP_TRAIN_COLS.write_text(json.dumps(column_meta, indent=2, default=str))
157
+ print(f" ✅ {OUT_APP_TRAIN_COLS}")
158
+
159
+ OUT_APP_TRAIN_CATEGORIES.write_text(json.dumps(categories, indent=2))
160
+ print(f" ✅ {OUT_APP_TRAIN_CATEGORIES}")
161
+
162
+ OUT_BINARY_MAPPINGS.write_text(json.dumps(binary_mappings, indent=2))
163
+ print(f" ✅ {OUT_BINARY_MAPPINGS}")
164
+ print("=" * 70)
165
+
166
+
167
+ if __name__ == "__main__":
168
+ main()
scripts/build_no_history_template.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Offline script: build the 'no-history' template for unknown clients.
2
+
3
+ For each aggregate column (bureau / prev / POS / CC / install), decide:
4
+ - COUNT-style columns → 0
5
+ - All other aggregates → NaN
6
+
7
+ This template is loaded once at API startup and used as the agg_part for
8
+ unknown SK_ID_CURR (Case 2 in the inference flow).
9
+
10
+ Run:
11
+ uv run python scripts/build_no_history_template.py
12
+
13
+ Depends on:
14
+ models/feature_names.json (produced by build_feature_store.py)
15
+ data/features_store.parquet (column reference)
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import json
21
+ import re
22
+ from pathlib import Path
23
+
24
+ import pandas as pd
25
+
26
+ ROOT = Path(__file__).resolve().parents[1]
27
+ FEATURE_NAMES_PATH = ROOT / "models" / "feature_names.json"
28
+ FEATURE_STORE_PATH = ROOT / "data" / "features_store.parquet"
29
+ OUT_TEMPLATE = ROOT / "models" / "no_history_template.json"
30
+
31
+ COUNT_PATTERN = re.compile(r"_COUNT$|_COUNT_|COUNT_$|^COUNT_")
32
+
33
+
34
+ def main() -> None:
35
+ feature_names = json.loads(FEATURE_NAMES_PATH.read_text())
36
+ store = pd.read_parquet(FEATURE_STORE_PATH)
37
+
38
+ aggregate_cols = [c for c in store.columns]
39
+ print(f"Inspecting {len(aggregate_cols)} aggregate columns...")
40
+
41
+ template: dict[str, float | int] = {}
42
+ count_cols: list[str] = []
43
+ nan_cols: list[str] = []
44
+
45
+ for col in aggregate_cols:
46
+ if COUNT_PATTERN.search(col):
47
+ template[col] = 0
48
+ count_cols.append(col)
49
+ else:
50
+ template[col] = None # serialised to JSON null → np.nan at load
51
+ nan_cols.append(col)
52
+
53
+ print(f" count-style (→ 0): {len(count_cols)}")
54
+ print(f" others (→ NaN) : {len(nan_cols)}")
55
+ print("\nSample count columns:", count_cols[:10])
56
+ print("Sample NaN columns: ", nan_cols[:5])
57
+
58
+ OUT_TEMPLATE.write_text(json.dumps(template, indent=2))
59
+ print(f"\n✅ {OUT_TEMPLATE} ({len(template)} entries)")
60
+
61
+ # Sanity check: every aggregate column from the store is also in feature_names
62
+ missing = [c for c in aggregate_cols if c not in feature_names]
63
+ if missing:
64
+ print(f"⚠️ {len(missing)} columns in parquet but absent from feature_names")
65
+ print(f" first 5: {missing[:5]}")
66
+
67
+
68
+ if __name__ == "__main__":
69
+ main()
scripts/check_registry.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import mlflow
2
+ from mlflow.tracking import MlflowClient
3
+
4
+ mlflow.set_tracking_uri("file:///C:/Users/Kevin/projects/OC_P6/mlruns")
5
+ client = MlflowClient()
6
+
7
+ # Liste tous les modèles enregistrés
8
+ models = client.search_registered_models()
9
+ print(f"Nombre de modèles enregistrés : {len(models)}")
10
+ for m in models:
11
+ print(f" - {m.name}")
12
+ for v in m.latest_versions:
13
+ print(f" version {v.version}, stage: {v.current_stage}, run_id: {v.run_id}")
scripts/export_model.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Exports the champion credit scoring model from OC_P6 to a local joblib file
3
+ for embedding in the OC_P8 deployment image.
4
+
5
+ Approach: bypass MLflow Server entirely. Load the model directly from the
6
+ filesystem using its physical path. Use MlflowClient only to fetch run-level
7
+ metadata (metrics, params) for traceability.
8
+ """
9
+
10
+ import json
11
+ from datetime import datetime
12
+ from pathlib import Path
13
+
14
+ import joblib
15
+ import mlflow
16
+ from mlflow.tracking import MlflowClient
17
+
18
+ # ============================================================
19
+ # Configuration
20
+ # ============================================================
21
+ P6_MLFLOW_TRACKING_URI = "http://127.0.0.1:5000"
22
+ MODEL_NAME = "lgbm_credit_scoring"
23
+ MODEL_VERSION = "2"
24
+
25
+ # Direct filesystem path to the model artifacts
26
+ # Adjust this if your model_id differs (check the "Source" output below)
27
+ P6_MODEL_PATH = Path(
28
+ "C:/Users/Kevin/projects/OC_P6/mlartifacts/3/models/"
29
+ "m-dbe6fc95d74c49a8bb4775a6b7516fcd/artifacts"
30
+ )
31
+
32
+ OUTPUT_DIR = Path("models")
33
+ OUTPUT_MODEL = OUTPUT_DIR / "model.joblib"
34
+ OUTPUT_INFO = OUTPUT_DIR / "model_info.json"
35
+
36
+ # ============================================================
37
+ # Setup
38
+ # ============================================================
39
+ mlflow.set_tracking_uri(P6_MLFLOW_TRACKING_URI)
40
+ client = MlflowClient()
41
+ OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
42
+
43
+ # ============================================================
44
+ # 1. Identify the model version (for metadata only)
45
+ # ============================================================
46
+ mv = client.get_model_version(MODEL_NAME, MODEL_VERSION)
47
+
48
+ print("=" * 60)
49
+ print("Model identified for export:")
50
+ print(f" Name : {mv.name}")
51
+ print(f" Version : {mv.version}")
52
+ print(f" Run ID : {mv.run_id}")
53
+ print(f" Source : {mv.source}")
54
+
55
+ run = client.get_run(mv.run_id)
56
+ print("\n Run metrics:")
57
+ for k, v in run.data.metrics.items():
58
+ print(f" {k}: {v:.4f}")
59
+
60
+ # ============================================================
61
+ # 2. Load the model — directly from filesystem (no HTTP, no Registry resolution)
62
+ # ============================================================
63
+ if not P6_MODEL_PATH.exists():
64
+ raise FileNotFoundError(
65
+ f"Model artifacts not found at: {P6_MODEL_PATH}\n"
66
+ f"Verify the path matches the 'Source' shown above."
67
+ )
68
+
69
+ print(f"\n Loading from filesystem: {P6_MODEL_PATH}")
70
+ model = mlflow.pyfunc.load_model(str(P6_MODEL_PATH))
71
+
72
+ print("\n Model signature:")
73
+ sig = model.metadata.signature
74
+ if sig is None:
75
+ print(" ⚠️ No signature logged - inputs will not be validated at inference!")
76
+ n_features = None
77
+ feature_names = None
78
+ else:
79
+ inputs = sig.inputs.to_dict()
80
+ n_features = len(inputs)
81
+ feature_names = [f["name"] for f in inputs]
82
+ print(f" Expected input features: {n_features}")
83
+ print(f" First 5 feature names: {feature_names[:5]}")
84
+
85
+ # ============================================================
86
+ # 3. Save the model locally
87
+ # ============================================================
88
+ joblib.dump(model, OUTPUT_MODEL)
89
+ size_mb = OUTPUT_MODEL.stat().st_size / 1e6
90
+ print(f"\n✅ Model saved to: {OUTPUT_MODEL} ({size_mb:.2f} MB)")
91
+
92
+ # ============================================================
93
+ # 4. Save provenance metadata
94
+ # ============================================================
95
+ info = {
96
+ "model_name": mv.name,
97
+ "version": mv.version,
98
+ "model_source": mv.source,
99
+ "run_id": mv.run_id,
100
+ "physical_path": str(P6_MODEL_PATH),
101
+ "exported_at": datetime.now().isoformat(),
102
+ "metrics": run.data.metrics,
103
+ "params": run.data.params,
104
+ "n_features_expected": n_features,
105
+ "feature_names": feature_names,
106
+ }
107
+ with open(OUTPUT_INFO, "w") as f:
108
+ json.dump(info, f, indent=2, default=str)
109
+ print(f"✅ Metadata saved to: {OUTPUT_INFO}")
110
+
111
+ print("=" * 60)
scripts/smoke_test_model.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Quick smoke test: reload the exported model and run a dummy prediction.
3
+ """
4
+ import joblib
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+ model = joblib.load("models/model.joblib")
9
+ print(f"✅ Model reloaded: {type(model)}")
10
+
11
+ # Dummy prediction with random features
12
+ # Adjust n_features if your model expects a specific count
13
+ n_features = 768
14
+ dummy = pd.DataFrame(np.random.randn(2, n_features), columns=[f"f_{i}" for i in range(n_features)])
15
+
16
+ try:
17
+ pred = model.predict(dummy)
18
+ print(f"✅ Prediction OK. Shape: {pred.shape}, sample values: {pred[:2]}")
19
+ except Exception as e:
20
+ print(f"❌ Prediction failed: {type(e).__name__}: {e}")
tests/__init__.py ADDED
File without changes
tests/conftest.py ADDED
@@ -0,0 +1,323 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Shared pytest fixtures.
2
+
3
+ Builds a minimal but realistic set of artefacts in tmp_path so tests run
4
+ without requiring the actual training data (~5 GB of CSVs).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ import joblib
14
+ import numpy as np
15
+ import pandas as pd
16
+ import pytest
17
+
18
+
19
+ # A tiny but valid app_train categories vocabulary — enough to exercise the
20
+ # one-hot logic without listing all 58 ORGANIZATION_TYPE values.
21
+ SYNTHETIC_CATEGORIES = {
22
+ "NAME_CONTRACT_TYPE": ["Cash loans", "Revolving loans"],
23
+ "NAME_TYPE_SUITE": ["Family", "Unaccompanied"],
24
+ "NAME_INCOME_TYPE": ["Pensioner", "State servant", "Working"],
25
+ "NAME_EDUCATION_TYPE": [
26
+ "Higher education",
27
+ "Lower secondary",
28
+ "Secondary / secondary special",
29
+ ],
30
+ "NAME_FAMILY_STATUS": ["Civil marriage", "Married", "Single / not married"],
31
+ "NAME_HOUSING_TYPE": ["House / apartment", "Rented apartment", "With parents"],
32
+ "OCCUPATION_TYPE": ["Accountants", "Core staff", "Laborers", "Managers"],
33
+ "WEEKDAY_APPR_PROCESS_START": ["MONDAY", "TUESDAY", "WEDNESDAY"],
34
+ "ORGANIZATION_TYPE": ["Business Entity Type 3", "Government", "School", "XNA"],
35
+ "FONDKAPREMONT_MODE": ["not specified", "reg oper account"],
36
+ "HOUSETYPE_MODE": ["block of flats", "terraced house"],
37
+ "WALLSMATERIAL_MODE": ["Block", "Panel", "Stone, brick"],
38
+ "EMERGENCYSTATE_MODE": ["No", "Yes"],
39
+ }
40
+
41
+ SYNTHETIC_BINARY_MAPPINGS = {
42
+ "CODE_GENDER": {"M": 0, "F": 1},
43
+ "FLAG_OWN_CAR": {"N": 0, "Y": 1},
44
+ "FLAG_OWN_REALTY": {"Y": 0, "N": 1},
45
+ }
46
+
47
+
48
+ # A realistic, valid payload accepted by api.schemas.PredictionRequest.
49
+ VALID_PAYLOAD: dict[str, Any] = {
50
+ "SK_ID_CURR": 100002,
51
+ "NAME_CONTRACT_TYPE": "Cash loans",
52
+ "CODE_GENDER": "M",
53
+ "FLAG_OWN_CAR": "N",
54
+ "FLAG_OWN_REALTY": "Y",
55
+ "CNT_CHILDREN": 0,
56
+ "AMT_INCOME_TOTAL": 202500.0,
57
+ "AMT_CREDIT": 406597.5,
58
+ "AMT_ANNUITY": 24700.5,
59
+ "AMT_GOODS_PRICE": 351000.0,
60
+ "NAME_TYPE_SUITE": "Unaccompanied",
61
+ "NAME_INCOME_TYPE": "Working",
62
+ "NAME_EDUCATION_TYPE": "Secondary / secondary special",
63
+ "NAME_FAMILY_STATUS": "Single / not married",
64
+ "NAME_HOUSING_TYPE": "House / apartment",
65
+ "REGION_POPULATION_RELATIVE": 0.018801,
66
+ "DAYS_BIRTH": -9461,
67
+ "DAYS_EMPLOYED": -637,
68
+ "DAYS_REGISTRATION": -3648.0,
69
+ "DAYS_ID_PUBLISH": -2120,
70
+ "OWN_CAR_AGE": None,
71
+ "FLAG_MOBIL": 1,
72
+ "FLAG_EMP_PHONE": 1,
73
+ "FLAG_WORK_PHONE": 0,
74
+ "FLAG_CONT_MOBILE": 1,
75
+ "FLAG_PHONE": 1,
76
+ "FLAG_EMAIL": 0,
77
+ "OCCUPATION_TYPE": "Laborers",
78
+ "CNT_FAM_MEMBERS": 1.0,
79
+ "REGION_RATING_CLIENT": 2,
80
+ "REGION_RATING_CLIENT_W_CITY": 2,
81
+ "WEEKDAY_APPR_PROCESS_START": "WEDNESDAY",
82
+ "HOUR_APPR_PROCESS_START": 10,
83
+ "REG_REGION_NOT_LIVE_REGION": 0,
84
+ "REG_REGION_NOT_WORK_REGION": 0,
85
+ "LIVE_REGION_NOT_WORK_REGION": 0,
86
+ "REG_CITY_NOT_LIVE_CITY": 0,
87
+ "REG_CITY_NOT_WORK_CITY": 0,
88
+ "LIVE_CITY_NOT_WORK_CITY": 0,
89
+ "ORGANIZATION_TYPE": "Business Entity Type 3",
90
+ "EXT_SOURCE_1": 0.0830,
91
+ "EXT_SOURCE_2": 0.2629,
92
+ "EXT_SOURCE_3": 0.1393,
93
+ "APARTMENTS_AVG": 0.0247,
94
+ "BASEMENTAREA_AVG": 0.0369,
95
+ "YEARS_BEGINEXPLUATATION_AVG": 0.9722,
96
+ "YEARS_BUILD_AVG": 0.6192,
97
+ "COMMONAREA_AVG": 0.0143,
98
+ "ELEVATORS_AVG": 0.0,
99
+ "ENTRANCES_AVG": 0.0690,
100
+ "FLOORSMAX_AVG": 0.0833,
101
+ "FLOORSMIN_AVG": 0.125,
102
+ "LANDAREA_AVG": 0.0369,
103
+ "LIVINGAPARTMENTS_AVG": 0.0205,
104
+ "LIVINGAREA_AVG": 0.0193,
105
+ "NONLIVINGAPARTMENTS_AVG": 0.0,
106
+ "NONLIVINGAREA_AVG": 0.0,
107
+ "APARTMENTS_MODE": 0.0252,
108
+ "BASEMENTAREA_MODE": 0.0383,
109
+ "YEARS_BEGINEXPLUATATION_MODE": 0.9722,
110
+ "YEARS_BUILD_MODE": 0.6341,
111
+ "COMMONAREA_MODE": 0.0144,
112
+ "ELEVATORS_MODE": 0.0,
113
+ "ENTRANCES_MODE": 0.0690,
114
+ "FLOORSMAX_MODE": 0.0833,
115
+ "FLOORSMIN_MODE": 0.125,
116
+ "LANDAREA_MODE": 0.0377,
117
+ "LIVINGAPARTMENTS_MODE": 0.022,
118
+ "LIVINGAREA_MODE": 0.0198,
119
+ "NONLIVINGAPARTMENTS_MODE": 0.0,
120
+ "NONLIVINGAREA_MODE": 0.0,
121
+ "APARTMENTS_MEDI": 0.025,
122
+ "BASEMENTAREA_MEDI": 0.0369,
123
+ "YEARS_BEGINEXPLUATATION_MEDI": 0.9722,
124
+ "YEARS_BUILD_MEDI": 0.6243,
125
+ "COMMONAREA_MEDI": 0.0144,
126
+ "ELEVATORS_MEDI": 0.0,
127
+ "ENTRANCES_MEDI": 0.069,
128
+ "FLOORSMAX_MEDI": 0.0833,
129
+ "FLOORSMIN_MEDI": 0.125,
130
+ "LANDAREA_MEDI": 0.0377,
131
+ "LIVINGAPARTMENTS_MEDI": 0.0205,
132
+ "LIVINGAREA_MEDI": 0.0198,
133
+ "NONLIVINGAPARTMENTS_MEDI": 0.0,
134
+ "NONLIVINGAREA_MEDI": 0.0,
135
+ "FONDKAPREMONT_MODE": "reg oper account",
136
+ "HOUSETYPE_MODE": "block of flats",
137
+ "TOTALAREA_MODE": 0.0149,
138
+ "WALLSMATERIAL_MODE": "Stone, brick",
139
+ "EMERGENCYSTATE_MODE": "No",
140
+ "OBS_30_CNT_SOCIAL_CIRCLE": 2.0,
141
+ "DEF_30_CNT_SOCIAL_CIRCLE": 2.0,
142
+ "OBS_60_CNT_SOCIAL_CIRCLE": 2.0,
143
+ "DEF_60_CNT_SOCIAL_CIRCLE": 2.0,
144
+ "DAYS_LAST_PHONE_CHANGE": -1134.0,
145
+ "FLAG_DOCUMENT_2": 0,
146
+ "FLAG_DOCUMENT_3": 1,
147
+ "FLAG_DOCUMENT_4": 0,
148
+ "FLAG_DOCUMENT_5": 0,
149
+ "FLAG_DOCUMENT_6": 0,
150
+ "FLAG_DOCUMENT_7": 0,
151
+ "FLAG_DOCUMENT_8": 0,
152
+ "FLAG_DOCUMENT_9": 0,
153
+ "FLAG_DOCUMENT_10": 0,
154
+ "FLAG_DOCUMENT_11": 0,
155
+ "FLAG_DOCUMENT_12": 0,
156
+ "FLAG_DOCUMENT_13": 0,
157
+ "FLAG_DOCUMENT_14": 0,
158
+ "FLAG_DOCUMENT_15": 0,
159
+ "FLAG_DOCUMENT_16": 0,
160
+ "FLAG_DOCUMENT_17": 0,
161
+ "FLAG_DOCUMENT_18": 0,
162
+ "FLAG_DOCUMENT_19": 0,
163
+ "FLAG_DOCUMENT_20": 0,
164
+ "FLAG_DOCUMENT_21": 0,
165
+ "AMT_REQ_CREDIT_BUREAU_HOUR": 0.0,
166
+ "AMT_REQ_CREDIT_BUREAU_DAY": 0.0,
167
+ "AMT_REQ_CREDIT_BUREAU_WEEK": 0.0,
168
+ "AMT_REQ_CREDIT_BUREAU_MON": 0.0,
169
+ "AMT_REQ_CREDIT_BUREAU_QRT": 0.0,
170
+ "AMT_REQ_CREDIT_BUREAU_YEAR": 1.0,
171
+ }
172
+
173
+
174
+ class FakeModel:
175
+ """Minimal stand-in for the real LightGBM PyFunc.
176
+
177
+ Returns a probability driven by AMT_INCOME_TOTAL / AMT_CREDIT so tests can
178
+ deterministically exercise both GRANTED and REFUSED branches.
179
+ """
180
+
181
+ def predict(self, df: pd.DataFrame) -> np.ndarray:
182
+ income = float(df.iloc[0].get("AMT_INCOME_TOTAL", 0) or 0)
183
+ credit = float(df.iloc[0].get("AMT_CREDIT", 1) or 1)
184
+ ratio = income / max(credit, 1)
185
+ proba_default = max(0.0, min(1.0, 1.0 - ratio))
186
+ return np.array([[1 - proba_default, proba_default]])
187
+
188
+
189
+ @pytest.fixture
190
+ def synthetic_feature_names() -> list[str]:
191
+ """Build a stable, ordered list of feature names matching the synthetic
192
+ artefacts. Mixes a handful of app_train one-hot columns + ratios + a few
193
+ aggregate columns (counts and a generic NaN-aggregate)."""
194
+ return [
195
+ # Numeric/binary fields kept as-is by transform_app_train_inputs
196
+ "CODE_GENDER",
197
+ "FLAG_OWN_CAR",
198
+ "FLAG_OWN_REALTY",
199
+ "CNT_CHILDREN",
200
+ "AMT_INCOME_TOTAL",
201
+ "AMT_CREDIT",
202
+ "AMT_ANNUITY",
203
+ "DAYS_BIRTH",
204
+ "DAYS_EMPLOYED",
205
+ "EXT_SOURCE_1",
206
+ "EXT_SOURCE_2",
207
+ "EXT_SOURCE_3",
208
+ "CNT_FAM_MEMBERS",
209
+ # Derived ratios
210
+ "DAYS_EMPLOYED_PERC",
211
+ "INCOME_CREDIT_PERC",
212
+ "INCOME_PER_PERSON",
213
+ "ANNUITY_INCOME_PERC",
214
+ "PAYMENT_RATE",
215
+ # Sample aggregate columns
216
+ "BURO_DAYS_CREDIT_MEAN",
217
+ "POS_COUNT",
218
+ "INSTAL_COUNT",
219
+ "CC_COUNT",
220
+ "PREV_AMT_ANNUITY_MEAN",
221
+ ]
222
+
223
+
224
+ @pytest.fixture
225
+ def synthetic_artefacts_dir(tmp_path: Path, synthetic_feature_names: list[str]) -> Path:
226
+ """Create a fully populated artefacts directory under tmp_path/.
227
+
228
+ Layout mirrors the project root so we can override settings paths
229
+ individually.
230
+ """
231
+ models_dir = tmp_path / "models"
232
+ data_dir = tmp_path / "data"
233
+ models_dir.mkdir()
234
+ data_dir.mkdir()
235
+
236
+ # 1. feature_names.json
237
+ (models_dir / "feature_names.json").write_text(json.dumps(synthetic_feature_names))
238
+
239
+ # 2. app_train_categories.json (multi-cat only)
240
+ (models_dir / "app_train_categories.json").write_text(json.dumps(SYNTHETIC_CATEGORIES))
241
+
242
+ # 3. app_train_binary_mappings.json
243
+ (models_dir / "app_train_binary_mappings.json").write_text(
244
+ json.dumps(SYNTHETIC_BINARY_MAPPINGS)
245
+ )
246
+
247
+ # 4. no_history_template.json — counts → 0, others → null (NaN once loaded)
248
+ template = {
249
+ "BURO_DAYS_CREDIT_MEAN": None,
250
+ "POS_COUNT": 0,
251
+ "INSTAL_COUNT": 0,
252
+ "CC_COUNT": 0,
253
+ "PREV_AMT_ANNUITY_MEAN": None,
254
+ }
255
+ (models_dir / "no_history_template.json").write_text(json.dumps(template))
256
+
257
+ # 5. Mini features_store.parquet — 2 known clients with realistic aggregates
258
+ feature_store = pd.DataFrame(
259
+ {
260
+ "BURO_DAYS_CREDIT_MEAN": [-1234.5, -890.2],
261
+ "POS_COUNT": [12, 5],
262
+ "INSTAL_COUNT": [25, 10],
263
+ "CC_COUNT": [3, 0],
264
+ "PREV_AMT_ANNUITY_MEAN": [15000.0, 8000.0],
265
+ },
266
+ index=pd.Index([100002, 100003], name="SK_ID_CURR"),
267
+ )
268
+ feature_store.to_parquet(data_dir / "features_store.parquet")
269
+
270
+ # 6. model.joblib — FakeModel
271
+ joblib.dump(FakeModel(), models_dir / "model.joblib")
272
+
273
+ # 7. model_info.json — minimal subset used by predictor + main routes
274
+ (models_dir / "model_info.json").write_text(
275
+ json.dumps(
276
+ {
277
+ "model_name": "fake_test_model",
278
+ "version": "test-1",
279
+ "metrics": {"best_threshold_mean": 0.33},
280
+ }
281
+ )
282
+ )
283
+
284
+ return tmp_path
285
+
286
+
287
+ @pytest.fixture
288
+ def patched_settings(monkeypatch, synthetic_artefacts_dir: Path) -> None:
289
+ """Point api.settings at the synthetic artefacts (re-import safe)."""
290
+ base = synthetic_artefacts_dir
291
+ monkeypatch.setenv("OC_P8_MODEL_PATH", str(base / "models" / "model.joblib"))
292
+ monkeypatch.setenv("OC_P8_MODEL_INFO_PATH", str(base / "models" / "model_info.json"))
293
+ monkeypatch.setenv(
294
+ "OC_P8_FEATURE_NAMES_PATH", str(base / "models" / "feature_names.json")
295
+ )
296
+ monkeypatch.setenv(
297
+ "OC_P8_APP_TRAIN_CATEGORIES_PATH",
298
+ str(base / "models" / "app_train_categories.json"),
299
+ )
300
+ monkeypatch.setenv(
301
+ "OC_P8_APP_TRAIN_BINARY_MAPPINGS_PATH",
302
+ str(base / "models" / "app_train_binary_mappings.json"),
303
+ )
304
+ monkeypatch.setenv(
305
+ "OC_P8_NO_HISTORY_TEMPLATE_PATH",
306
+ str(base / "models" / "no_history_template.json"),
307
+ )
308
+ monkeypatch.setenv(
309
+ "OC_P8_FEATURE_STORE_PATH", str(base / "data" / "features_store.parquet")
310
+ )
311
+
312
+ # Force a fresh import of api.settings so it picks up the env vars.
313
+ import importlib
314
+
315
+ import api.settings as s
316
+
317
+ importlib.reload(s)
318
+
319
+
320
+ @pytest.fixture
321
+ def valid_payload() -> dict[str, Any]:
322
+ """Return a fresh copy of the canonical valid request payload."""
323
+ return dict(VALID_PAYLOAD)
tests/integration/__init__.py ADDED
File without changes
tests/integration/test_api.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Integration tests that boot the FastAPI app via TestClient.
2
+
3
+ The app is configured to use synthetic artefacts via env vars, so these
4
+ tests run in seconds and don't need the real 5 GB of training data.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import importlib
10
+
11
+ import pytest
12
+ from fastapi.testclient import TestClient
13
+
14
+
15
+ @pytest.fixture
16
+ def client(patched_settings): # patched_settings sets the env vars first
17
+ """Build a TestClient against a freshly-loaded app.
18
+
19
+ Re-import api.main so it picks up the patched api.settings module.
20
+ """
21
+ import api.main as main_module
22
+
23
+ importlib.reload(main_module)
24
+ with TestClient(main_module.app) as test_client:
25
+ yield test_client
26
+
27
+
28
+ def test_health_endpoint(client):
29
+ resp = client.get("/health")
30
+ assert resp.status_code == 200
31
+ payload = resp.json()
32
+ assert payload["status"] == "ok"
33
+ assert payload["model_version"] == "test-1"
34
+
35
+
36
+ def test_swagger_docs_available(client):
37
+ """The brief explicitly requires Swagger documentation."""
38
+ resp = client.get("/docs")
39
+ assert resp.status_code == 200
40
+
41
+
42
+ def test_openapi_schema(client):
43
+ resp = client.get("/openapi.json")
44
+ assert resp.status_code == 200
45
+ schema = resp.json()
46
+ assert "/predict" in schema["paths"]
47
+
48
+
49
+ def test_model_info_endpoint(client):
50
+ resp = client.get("/model/info")
51
+ assert resp.status_code == 200
52
+ payload = resp.json()
53
+ assert payload["threshold"] == 0.33
54
+ assert payload["version"] == "test-1"
55
+ assert payload["n_features_expected"] > 0
56
+
57
+
58
+ def test_predict_known_client(client, valid_payload):
59
+ resp = client.post("/predict", json=valid_payload)
60
+ assert resp.status_code == 200, resp.text
61
+ payload = resp.json()
62
+ assert payload["sk_id_curr"] == valid_payload["SK_ID_CURR"]
63
+ assert payload["client_known"] is True
64
+ assert payload["decision"] in {"GRANTED", "REFUSED"}
65
+ assert 0.0 <= payload["probability_default"] <= 1.0
66
+ assert payload["threshold"] == 0.33
67
+ assert payload["model_version"] == "test-1"
68
+
69
+
70
+ def test_predict_unknown_client(client, valid_payload):
71
+ valid_payload["SK_ID_CURR"] = 999_999_999 # absent from synthetic feature store
72
+ resp = client.post("/predict", json=valid_payload)
73
+ assert resp.status_code == 200, resp.text
74
+ assert resp.json()["client_known"] is False
75
+
76
+
77
+ def test_predict_rejects_negative_income(client, valid_payload):
78
+ valid_payload["AMT_INCOME_TOTAL"] = -1.0
79
+ resp = client.post("/predict", json=valid_payload)
80
+ assert resp.status_code == 422
81
+
82
+
83
+ def test_predict_rejects_missing_required_field(client, valid_payload):
84
+ del valid_payload["DAYS_BIRTH"]
85
+ resp = client.post("/predict", json=valid_payload)
86
+ assert resp.status_code == 422
87
+
88
+
89
+ def test_predict_rejects_extra_field(client, valid_payload):
90
+ valid_payload["__injection__"] = "evil"
91
+ resp = client.post("/predict", json=valid_payload)
92
+ assert resp.status_code == 422
93
+
94
+
95
+ def test_predict_rejects_unknown_contract_type(client, valid_payload):
96
+ valid_payload["NAME_CONTRACT_TYPE"] = "Bitcoin loans"
97
+ resp = client.post("/predict", json=valid_payload)
98
+ assert resp.status_code == 422
tests/unit/__init__.py ADDED
File without changes
tests/unit/test_inference_assembler.py ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for the inference assembler — the core branching logic
2
+ between known clients (parquet lookup) and unknown clients (no-history)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import numpy as np
7
+ import pandas as pd
8
+
9
+ from api.inference_assembler import InferenceArtefacts, assemble
10
+
11
+
12
+ def _build_artefacts(synthetic_artefacts_dir):
13
+ base = synthetic_artefacts_dir
14
+ return InferenceArtefacts.load(
15
+ feature_names_path=base / "models" / "feature_names.json",
16
+ categories_path=base / "models" / "app_train_categories.json",
17
+ binary_mappings_path=base / "models" / "app_train_binary_mappings.json",
18
+ no_history_template_path=base / "models" / "no_history_template.json",
19
+ feature_store_path=base / "data" / "features_store.parquet",
20
+ )
21
+
22
+
23
+ def test_known_client_pulls_from_feature_store(synthetic_artefacts_dir, valid_payload):
24
+ artefacts = _build_artefacts(synthetic_artefacts_dir)
25
+ raw = dict(valid_payload)
26
+ sk_id = raw.pop("SK_ID_CURR") # 100002 — known in synthetic store
27
+
28
+ features, client_known = assemble(raw, sk_id_curr=sk_id, artefacts=artefacts)
29
+
30
+ assert client_known is True
31
+ # Aggregates must come from the parquet, not the template
32
+ assert features["BURO_DAYS_CREDIT_MEAN"].iloc[0] == -1234.5
33
+ assert int(features["POS_COUNT"].iloc[0]) == 12
34
+ assert features["PREV_AMT_ANNUITY_MEAN"].iloc[0] == 15000.0
35
+
36
+
37
+ def test_unknown_client_uses_no_history_template(synthetic_artefacts_dir, valid_payload):
38
+ artefacts = _build_artefacts(synthetic_artefacts_dir)
39
+ raw = dict(valid_payload)
40
+ raw.pop("SK_ID_CURR")
41
+
42
+ features, client_known = assemble(raw, sk_id_curr=999_999_999, artefacts=artefacts)
43
+
44
+ assert client_known is False
45
+ # Counts default to 0
46
+ assert int(features["POS_COUNT"].iloc[0]) == 0
47
+ assert int(features["INSTAL_COUNT"].iloc[0]) == 0
48
+ assert int(features["CC_COUNT"].iloc[0]) == 0
49
+ # Numeric aggregates default to NaN — preserves the training "no history" signal
50
+ assert np.isnan(features["BURO_DAYS_CREDIT_MEAN"].iloc[0])
51
+ assert np.isnan(features["PREV_AMT_ANNUITY_MEAN"].iloc[0])
52
+
53
+
54
+ def test_output_columns_are_in_feature_names_order(synthetic_artefacts_dir, valid_payload):
55
+ artefacts = _build_artefacts(synthetic_artefacts_dir)
56
+ raw = dict(valid_payload)
57
+ raw.pop("SK_ID_CURR")
58
+ features, _ = assemble(raw, sk_id_curr=100002, artefacts=artefacts)
59
+ assert list(features.columns) == artefacts.feature_names
60
+
61
+
62
+ def test_derived_ratios_reflect_overrides(synthetic_artefacts_dir, valid_payload):
63
+ """If the JSON overrides AMT_INCOME_TOTAL, the ratio columns must use the
64
+ new value rather than any stale stored data."""
65
+ artefacts = _build_artefacts(synthetic_artefacts_dir)
66
+ raw = dict(valid_payload)
67
+ raw["AMT_INCOME_TOTAL"] = 100_000.0
68
+ raw["AMT_CREDIT"] = 200_000.0
69
+ raw["AMT_ANNUITY"] = 10_000.0
70
+ raw.pop("SK_ID_CURR")
71
+
72
+ features, _ = assemble(raw, sk_id_curr=100002, artefacts=artefacts)
73
+ row = features.iloc[0]
74
+ assert row["INCOME_CREDIT_PERC"] == 0.5
75
+ assert row["PAYMENT_RATE"] == 0.05
76
+
77
+
78
+ def test_unknown_categorical_values_do_not_crash(
79
+ synthetic_artefacts_dir, valid_payload
80
+ ):
81
+ """A new ORGANIZATION_TYPE value not seen in training must coerce silently
82
+ rather than break assembly — pd.Categorical handles this by emitting NaN."""
83
+ artefacts = _build_artefacts(synthetic_artefacts_dir)
84
+ raw = dict(valid_payload)
85
+ raw["ORGANIZATION_TYPE"] = "Mars Colony"
86
+ raw.pop("SK_ID_CURR")
87
+ features, _ = assemble(raw, sk_id_curr=100002, artefacts=artefacts)
88
+ assert isinstance(features, pd.DataFrame)
89
+
90
+
91
+ def test_inf_values_replaced_with_nan(synthetic_artefacts_dir, valid_payload):
92
+ """Edge case: AMT_CREDIT=0 produces inf in PAYMENT_RATE; assembler scrubs."""
93
+ artefacts = _build_artefacts(synthetic_artefacts_dir)
94
+ raw = dict(valid_payload)
95
+ raw["AMT_CREDIT"] = 0.0001 # tiny but non-zero to keep Pydantic happy upstream
96
+ raw.pop("SK_ID_CURR")
97
+ features, _ = assemble(raw, sk_id_curr=100002, artefacts=artefacts)
98
+ for col in ("DAYS_EMPLOYED_PERC", "INCOME_CREDIT_PERC", "PAYMENT_RATE"):
99
+ val = features[col].iloc[0]
100
+ assert not np.isinf(val), f"{col} is inf"
tests/unit/test_inputs_transform.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for the runtime app_train transformation.
2
+
3
+ The critical property under test is the one-hot pitfall fix: a single-row
4
+ input must produce one column for EVERY known training category, not just
5
+ the one currently present.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import numpy as np
11
+
12
+ from api.inputs_transform import transform_app_train_inputs
13
+
14
+ CATS = {
15
+ "NAME_CONTRACT_TYPE": ["Cash loans", "Revolving loans"],
16
+ "NAME_INCOME_TYPE": ["Pensioner", "Working", "State servant"],
17
+ "ORGANIZATION_TYPE": ["Bank", "School", "XNA"],
18
+ }
19
+ BINARY = {
20
+ "CODE_GENDER": {"M": 0, "F": 1},
21
+ "FLAG_OWN_CAR": {"N": 0, "Y": 1},
22
+ "FLAG_OWN_REALTY": {"Y": 0, "N": 1},
23
+ }
24
+
25
+
26
+ def test_binary_columns_factorized_with_training_codes():
27
+ raw = {"CODE_GENDER": "F", "FLAG_OWN_CAR": "Y", "FLAG_OWN_REALTY": "N"}
28
+ out = transform_app_train_inputs(raw, CATS, BINARY)
29
+ assert int(out["CODE_GENDER"].iloc[0]) == 1
30
+ assert int(out["FLAG_OWN_CAR"].iloc[0]) == 1
31
+ assert int(out["FLAG_OWN_REALTY"].iloc[0]) == 1
32
+
33
+
34
+ def test_one_hot_emits_all_known_categories_even_with_one_row():
35
+ """The whole point of pd.Categorical(categories=KNOWN): every training
36
+ category becomes a column regardless of what the row contains."""
37
+ raw = {"NAME_CONTRACT_TYPE": "Cash loans"}
38
+ out = transform_app_train_inputs(raw, CATS, BINARY)
39
+ assert "NAME_CONTRACT_TYPE_Cash loans" in out.columns
40
+ assert "NAME_CONTRACT_TYPE_Revolving loans" in out.columns
41
+ assert int(out["NAME_CONTRACT_TYPE_Cash loans"].iloc[0]) == 1
42
+ assert int(out["NAME_CONTRACT_TYPE_Revolving loans"].iloc[0]) == 0
43
+
44
+
45
+ def test_unknown_category_value_becomes_zero_everywhere():
46
+ """If the JSON sends a value never seen in training, it's coerced to NaN
47
+ by pd.Categorical, then get_dummies emits all-zero columns."""
48
+ raw = {"ORGANIZATION_TYPE": "Mars Colony"}
49
+ out = transform_app_train_inputs(raw, CATS, BINARY)
50
+ assert int(out["ORGANIZATION_TYPE_Bank"].iloc[0]) == 0
51
+ assert int(out["ORGANIZATION_TYPE_School"].iloc[0]) == 0
52
+ assert int(out["ORGANIZATION_TYPE_XNA"].iloc[0]) == 0
53
+
54
+
55
+ def test_days_employed_sentinel_replaced_with_nan():
56
+ raw = {"DAYS_EMPLOYED": 365243}
57
+ out = transform_app_train_inputs(raw, CATS, BINARY)
58
+ assert np.isnan(out["DAYS_EMPLOYED"].iloc[0])
59
+
60
+
61
+ def test_days_employed_normal_value_preserved():
62
+ raw = {"DAYS_EMPLOYED": -1500}
63
+ out = transform_app_train_inputs(raw, CATS, BINARY)
64
+ assert int(out["DAYS_EMPLOYED"].iloc[0]) == -1500
65
+
66
+
67
+ def test_output_is_single_row():
68
+ raw = {"NAME_CONTRACT_TYPE": "Cash loans"}
69
+ out = transform_app_train_inputs(raw, CATS, BINARY)
70
+ assert len(out) == 1
tests/unit/test_predictor.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for CreditScoringPredictor."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from pathlib import Path
7
+
8
+ import joblib
9
+ import numpy as np
10
+ import pandas as pd
11
+ import pytest
12
+
13
+ from api.predictor import CreditScoringPredictor
14
+
15
+
16
+ class _FixedProbModel:
17
+ def __init__(self, proba: float) -> None:
18
+ self.proba = proba
19
+
20
+ def predict(self, df: pd.DataFrame) -> np.ndarray:
21
+ return np.array([[1 - self.proba, self.proba]])
22
+
23
+
24
+ class _WeirdModel:
25
+ def predict(self, df: pd.DataFrame) -> np.ndarray:
26
+ return np.array([[[0.1, 0.9]]]) # 3D — invalid
27
+
28
+
29
+ class _FlatModel:
30
+ def predict(self, df: pd.DataFrame) -> np.ndarray:
31
+ return np.array([0.6])
32
+
33
+
34
+ def _write_model_info(path: Path, threshold: float, version: str = "test-1") -> None:
35
+ path.write_text(
36
+ json.dumps(
37
+ {
38
+ "model_name": "fake",
39
+ "version": version,
40
+ "metrics": {"best_threshold_mean": threshold},
41
+ }
42
+ )
43
+ )
44
+
45
+
46
+ def _build(tmp_path: Path, proba: float, threshold: float) -> CreditScoringPredictor:
47
+ model_path = tmp_path / "model.joblib"
48
+ info_path = tmp_path / "info.json"
49
+ joblib.dump(_FixedProbModel(proba), model_path)
50
+ _write_model_info(info_path, threshold)
51
+ return CreditScoringPredictor.load(
52
+ model_path=model_path, model_info_path=info_path, default_threshold=0.5
53
+ )
54
+
55
+
56
+ def test_threshold_loaded_from_model_info(tmp_path):
57
+ pred = _build(tmp_path, proba=0.1, threshold=0.42)
58
+ assert pred.threshold == 0.42
59
+
60
+
61
+ def test_threshold_falls_back_to_default(tmp_path):
62
+ """If model_info lacks best_threshold_mean, default applies."""
63
+ info = tmp_path / "info.json"
64
+ info.write_text(json.dumps({"model_name": "fake", "version": "1", "metrics": {}}))
65
+ model = tmp_path / "model.joblib"
66
+ joblib.dump(_FixedProbModel(0.0), model)
67
+ pred = CreditScoringPredictor.load(model, info, default_threshold=0.7)
68
+ assert pred.threshold == 0.7
69
+
70
+
71
+ def test_decision_granted_below_threshold(tmp_path):
72
+ pred = _build(tmp_path, proba=0.1, threshold=0.33)
73
+ proba, decision = pred.predict(pd.DataFrame([{}]))
74
+ assert proba == pytest.approx(0.1)
75
+ assert decision == "GRANTED"
76
+
77
+
78
+ def test_decision_refused_above_threshold(tmp_path):
79
+ pred = _build(tmp_path, proba=0.5, threshold=0.33)
80
+ proba, decision = pred.predict(pd.DataFrame([{}]))
81
+ assert decision == "REFUSED"
82
+
83
+
84
+ def test_decision_at_threshold_is_refused(tmp_path):
85
+ """proba >= threshold → REFUSED (boundary test)."""
86
+ pred = _build(tmp_path, proba=0.33, threshold=0.33)
87
+ _, decision = pred.predict(pd.DataFrame([{}]))
88
+ assert decision == "REFUSED"
89
+
90
+
91
+ def test_proba_in_unit_interval(tmp_path):
92
+ pred = _build(tmp_path, proba=0.42, threshold=0.5)
93
+ proba, _ = pred.predict(pd.DataFrame([{}]))
94
+ assert 0.0 <= proba <= 1.0
95
+
96
+
97
+ def test_unexpected_prediction_shape_raises(tmp_path):
98
+ info = tmp_path / "info.json"
99
+ _write_model_info(info, 0.5)
100
+ model = tmp_path / "model.joblib"
101
+ joblib.dump(_WeirdModel(), model)
102
+ pred = CreditScoringPredictor.load(model, info, default_threshold=0.5)
103
+ with pytest.raises(ValueError, match="Unexpected prediction shape"):
104
+ pred.predict(pd.DataFrame([{}]))
105
+
106
+
107
+ def test_1d_array_prediction_supported(tmp_path):
108
+ """Some PyFunc wrappers return a 1D probability array — supported too."""
109
+ info = tmp_path / "info.json"
110
+ _write_model_info(info, 0.5)
111
+ model = tmp_path / "model.joblib"
112
+ joblib.dump(_FlatModel(), model)
113
+ pred = CreditScoringPredictor.load(model, info, default_threshold=0.5)
114
+ proba, decision = pred.predict(pd.DataFrame([{}]))
115
+ assert proba == pytest.approx(0.6)
116
+ assert decision == "REFUSED"
tests/unit/test_ratios.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Unit tests for the 5 derived-ratio formulas."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+ import pytest
8
+
9
+ from api.ratios import apply_derived_ratios
10
+
11
+
12
+ def _row(**overrides) -> pd.DataFrame:
13
+ base = {
14
+ "DAYS_EMPLOYED": -637.0,
15
+ "DAYS_BIRTH": -9461.0,
16
+ "AMT_INCOME_TOTAL": 200000.0,
17
+ "AMT_CREDIT": 400000.0,
18
+ "AMT_ANNUITY": 25000.0,
19
+ "CNT_FAM_MEMBERS": 2.0,
20
+ }
21
+ base.update(overrides)
22
+ return pd.DataFrame([base])
23
+
24
+
25
+ def test_all_five_ratios_present():
26
+ out = apply_derived_ratios(_row())
27
+ expected = {
28
+ "DAYS_EMPLOYED_PERC",
29
+ "INCOME_CREDIT_PERC",
30
+ "INCOME_PER_PERSON",
31
+ "ANNUITY_INCOME_PERC",
32
+ "PAYMENT_RATE",
33
+ }
34
+ assert expected.issubset(out.columns)
35
+
36
+
37
+ def test_known_values():
38
+ out = apply_derived_ratios(_row())
39
+ row = out.iloc[0]
40
+ assert row["DAYS_EMPLOYED_PERC"] == pytest.approx(-637.0 / -9461.0)
41
+ assert row["INCOME_CREDIT_PERC"] == pytest.approx(200000 / 400000)
42
+ assert row["INCOME_PER_PERSON"] == pytest.approx(200000 / 2)
43
+ assert row["ANNUITY_INCOME_PERC"] == pytest.approx(25000 / 200000)
44
+ assert row["PAYMENT_RATE"] == pytest.approx(25000 / 400000)
45
+
46
+
47
+ def test_division_by_zero_returns_nan():
48
+ out = apply_derived_ratios(_row(AMT_CREDIT=0))
49
+ row = out.iloc[0]
50
+ assert pd.isna(row["INCOME_CREDIT_PERC"])
51
+ assert pd.isna(row["PAYMENT_RATE"])
52
+
53
+
54
+ def test_nan_propagates():
55
+ out = apply_derived_ratios(_row(DAYS_EMPLOYED=np.nan))
56
+ assert pd.isna(out.iloc[0]["DAYS_EMPLOYED_PERC"])
57
+
58
+
59
+ def test_input_dataframe_not_mutated():
60
+ df = _row()
61
+ snapshot = df.copy()
62
+ _ = apply_derived_ratios(df)
63
+ pd.testing.assert_frame_equal(df, snapshot)
tests/unit/test_schemas.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Schema validation tests — make sure the Pydantic ranges actually catch
2
+ the bad inputs the brief calls out (negative income, age out-of-range, etc.)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import pytest
7
+ from pydantic import ValidationError
8
+
9
+ from api.schemas import PredictionRequest
10
+
11
+
12
+ def test_valid_payload_accepted(valid_payload):
13
+ PredictionRequest(**valid_payload)
14
+
15
+
16
+ def test_negative_income_rejected(valid_payload):
17
+ valid_payload["AMT_INCOME_TOTAL"] = -100
18
+ with pytest.raises(ValidationError):
19
+ PredictionRequest(**valid_payload)
20
+
21
+
22
+ def test_zero_credit_rejected(valid_payload):
23
+ valid_payload["AMT_CREDIT"] = 0
24
+ with pytest.raises(ValidationError):
25
+ PredictionRequest(**valid_payload)
26
+
27
+
28
+ def test_age_under_18_rejected(valid_payload):
29
+ """DAYS_BIRTH ge -6570 enforces age ≤ 18 yr (closer to today)."""
30
+ valid_payload["DAYS_BIRTH"] = -100 # roughly 3 months old
31
+ with pytest.raises(ValidationError):
32
+ PredictionRequest(**valid_payload)
33
+
34
+
35
+ def test_age_over_70_rejected(valid_payload):
36
+ valid_payload["DAYS_BIRTH"] = -30000 # ~82 years
37
+ with pytest.raises(ValidationError):
38
+ PredictionRequest(**valid_payload)
39
+
40
+
41
+ def test_unknown_contract_type_rejected(valid_payload):
42
+ valid_payload["NAME_CONTRACT_TYPE"] = "Some unknown type"
43
+ with pytest.raises(ValidationError):
44
+ PredictionRequest(**valid_payload)
45
+
46
+
47
+ def test_extra_field_rejected(valid_payload):
48
+ valid_payload["__hacker_field__"] = 42
49
+ with pytest.raises(ValidationError):
50
+ PredictionRequest(**valid_payload)
51
+
52
+
53
+ def test_optional_fields_accept_null(valid_payload):
54
+ valid_payload["EXT_SOURCE_1"] = None
55
+ valid_payload["OWN_CAR_AGE"] = None
56
+ PredictionRequest(**valid_payload)
57
+
58
+
59
+ def test_flag_must_be_zero_or_one(valid_payload):
60
+ valid_payload["FLAG_DOCUMENT_3"] = 5
61
+ with pytest.raises(ValidationError):
62
+ PredictionRequest(**valid_payload)
63
+
64
+
65
+ def test_required_field_missing(valid_payload):
66
+ del valid_payload["DAYS_BIRTH"]
67
+ with pytest.raises(ValidationError):
68
+ PredictionRequest(**valid_payload)
uv.lock ADDED
The diff for this file is too large to render. See raw diff