Spaces:
Sleeping
Sleeping
Upload processing.py
Browse files- processing.py +17 -19
processing.py
CHANGED
|
@@ -63,31 +63,31 @@ def map_statut_expert(p2):
|
|
| 63 |
# --- 3. PRÉPARATION DES DONNÉES (La version robuste) ---
|
| 64 |
|
| 65 |
def prepare_input(data):
|
| 66 |
-
# 1.
|
| 67 |
-
# FEATURES
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
else:
|
| 77 |
-
# Si par hasard ton secret FEATURES contient 'age_estime'
|
| 78 |
-
df['age_estime'] = valeur_age
|
| 79 |
|
|
|
|
|
|
|
|
|
|
| 80 |
df['Tranche_effectif_num'] = float(data.get('Tranche_effectif_num', 0))
|
| 81 |
df['is_ess'] = int(data.get('is_ess', 0))
|
| 82 |
|
| 83 |
-
#
|
| 84 |
code_dep = str(data.get('code_departement', '')).strip().upper()
|
| 85 |
df['risque_departemental'] = float(DEP_RISK_MAP.get(code_dep, 0.05))
|
| 86 |
|
| 87 |
-
#
|
| 88 |
code_ape = str(data.get('code_ape', '')).zfill(2)
|
| 89 |
section_name = APE_SECTION_MAP.get(code_ape)
|
| 90 |
-
|
| 91 |
if section_name:
|
| 92 |
col_ape = f"APE_{section_name}"
|
| 93 |
if col_ape in df.columns:
|
|
@@ -95,12 +95,10 @@ def prepare_input(data):
|
|
| 95 |
elif 'APE_Autres_Secteurs' in df.columns:
|
| 96 |
df['APE_Autres_Secteurs'] = 1.0
|
| 97 |
|
| 98 |
-
#
|
| 99 |
cj_prefix = str(data.get('categorie_juridique', ''))[:4]
|
| 100 |
col_cj = f"CJ_{cj_prefix}"
|
| 101 |
if col_cj in df.columns:
|
| 102 |
df[col_cj] = 1.0
|
| 103 |
-
elif 'CJ_Autres_Status' in df.columns:
|
| 104 |
-
df['CJ_Autres_Status'] = 1.0
|
| 105 |
|
| 106 |
-
return xgb.DMatrix(df)
|
|
|
|
| 63 |
# --- 3. PRÉPARATION DES DONNÉES (La version robuste) ---
|
| 64 |
|
| 65 |
def prepare_input(data):
|
| 66 |
+
# 1. On définit la liste EXACTE telle que le modèle l'attend (ordre de l'erreur 500)
|
| 67 |
+
# On filtre les FEATURES pour enlever ce qui n'est pas utilisé par XGBoost
|
| 68 |
+
cols_to_exclude = ["SIREN", "Dénomination de l'unité légale"]
|
| 69 |
+
model_columns = [c for c in FEATURES if c not in cols_to_exclude]
|
| 70 |
|
| 71 |
+
# Sécurité : Si l'âge n'est pas dans ton JSON, on l'ajoute pour correspondre au modèle
|
| 72 |
+
if 'age_au_diagnostic' not in model_columns:
|
| 73 |
+
model_columns.append('age_au_diagnostic')
|
| 74 |
+
|
| 75 |
+
# 2. Création du DataFrame avec cet ordre STRICT
|
| 76 |
+
df = pd.DataFrame(0.0, index=[0], columns=model_columns)
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
# 3. Remplissage chirurgical
|
| 79 |
+
# On utilise age_estime venant du Streamlit pour remplir age_au_diagnostic
|
| 80 |
+
df['age_au_diagnostic'] = float(data.get('age_estime', 0))
|
| 81 |
df['Tranche_effectif_num'] = float(data.get('Tranche_effectif_num', 0))
|
| 82 |
df['is_ess'] = int(data.get('is_ess', 0))
|
| 83 |
|
| 84 |
+
# Risque départemental
|
| 85 |
code_dep = str(data.get('code_departement', '')).strip().upper()
|
| 86 |
df['risque_departemental'] = float(DEP_RISK_MAP.get(code_dep, 0.05))
|
| 87 |
|
| 88 |
+
# Mapping APE
|
| 89 |
code_ape = str(data.get('code_ape', '')).zfill(2)
|
| 90 |
section_name = APE_SECTION_MAP.get(code_ape)
|
|
|
|
| 91 |
if section_name:
|
| 92 |
col_ape = f"APE_{section_name}"
|
| 93 |
if col_ape in df.columns:
|
|
|
|
| 95 |
elif 'APE_Autres_Secteurs' in df.columns:
|
| 96 |
df['APE_Autres_Secteurs'] = 1.0
|
| 97 |
|
| 98 |
+
# Mapping CJ
|
| 99 |
cj_prefix = str(data.get('categorie_juridique', ''))[:4]
|
| 100 |
col_cj = f"CJ_{cj_prefix}"
|
| 101 |
if col_cj in df.columns:
|
| 102 |
df[col_cj] = 1.0
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
return xgb.DMatrix(df[model_columns])
|