Spaces:
Sleeping
Sleeping
Upload processing.py
Browse files- processing.py +16 -13
processing.py
CHANGED
|
@@ -63,18 +63,18 @@ def map_statut_expert(p2):
|
|
| 63 |
# --- 3. PRÉPARATION DES DONNÉES (La version robuste) ---
|
| 64 |
|
| 65 |
def prepare_input(data):
|
| 66 |
-
# 1. On définit
|
| 67 |
-
# On retire SIREN et Dénomination
|
| 68 |
-
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
if "age_au_diagnostic" not in
|
| 72 |
-
|
| 73 |
|
| 74 |
-
# 2.
|
| 75 |
-
df = pd.DataFrame(0.0, index=[0], columns=
|
| 76 |
|
| 77 |
-
# 3.
|
| 78 |
df['age_au_diagnostic'] = float(data.get('age_estime', 0))
|
| 79 |
df['Tranche_effectif_num'] = float(data.get('Tranche_effectif_num', 0))
|
| 80 |
df['is_ess'] = int(data.get('is_ess', 0))
|
|
@@ -83,7 +83,7 @@ def prepare_input(data):
|
|
| 83 |
code_dep = str(data.get('code_departement', '')).strip().upper()
|
| 84 |
df['risque_departemental'] = float(DEP_RISK_MAP.get(code_dep, 0.05))
|
| 85 |
|
| 86 |
-
#
|
| 87 |
code_ape = str(data.get('code_ape', '')).zfill(2)
|
| 88 |
section_name = APE_SECTION_MAP.get(code_ape)
|
| 89 |
if section_name:
|
|
@@ -93,11 +93,14 @@ def prepare_input(data):
|
|
| 93 |
else:
|
| 94 |
df['APE_Autres_Secteurs'] = 1.0
|
| 95 |
|
| 96 |
-
#
|
| 97 |
cj_prefix = str(data.get('categorie_juridique', ''))[:4]
|
| 98 |
col_cj = f"CJ_{cj_prefix}"
|
| 99 |
if col_cj in df.columns:
|
| 100 |
df[col_cj] = 1.0
|
| 101 |
|
| 102 |
-
# 4.
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# --- 3. PRÉPARATION DES DONNÉES (La version robuste) ---
|
| 64 |
|
| 65 |
def prepare_input(data):
|
| 66 |
+
# 1. On définit l'ordre EXACT attendu par le modèle (ordre de ton erreur 500)
|
| 67 |
+
# On retire SIREN et Dénomination qui polluent le début de ta liste
|
| 68 |
+
clean_features = [c for c in FEATURES if c not in ["SIREN", "Dénomination de l'unité légale"]]
|
| 69 |
|
| 70 |
+
# On s'assure que l'âge est bien à la fin si c'est là qu'il était lors de l'erreur
|
| 71 |
+
if "age_au_diagnostic" not in clean_features:
|
| 72 |
+
clean_features.append("age_au_diagnostic")
|
| 73 |
|
| 74 |
+
# 2. On crée le DataFrame avec cet ordre
|
| 75 |
+
df = pd.DataFrame(0.0, index=[0], columns=clean_features)
|
| 76 |
|
| 77 |
+
# 3. On remplit les valeurs par NOM
|
| 78 |
df['age_au_diagnostic'] = float(data.get('age_estime', 0))
|
| 79 |
df['Tranche_effectif_num'] = float(data.get('Tranche_effectif_num', 0))
|
| 80 |
df['is_ess'] = int(data.get('is_ess', 0))
|
|
|
|
| 83 |
code_dep = str(data.get('code_departement', '')).strip().upper()
|
| 84 |
df['risque_departemental'] = float(DEP_RISK_MAP.get(code_dep, 0.05))
|
| 85 |
|
| 86 |
+
# Mapping APE (Secteur)
|
| 87 |
code_ape = str(data.get('code_ape', '')).zfill(2)
|
| 88 |
section_name = APE_SECTION_MAP.get(code_ape)
|
| 89 |
if section_name:
|
|
|
|
| 93 |
else:
|
| 94 |
df['APE_Autres_Secteurs'] = 1.0
|
| 95 |
|
| 96 |
+
# Mapping CJ (Juridique)
|
| 97 |
cj_prefix = str(data.get('categorie_juridique', ''))[:4]
|
| 98 |
col_cj = f"CJ_{cj_prefix}"
|
| 99 |
if col_cj in df.columns:
|
| 100 |
df[col_cj] = 1.0
|
| 101 |
|
| 102 |
+
# 4. LE POINT CRITIQUE : on réordonne les colonnes avant de créer la DMatrix
|
| 103 |
+
# Cela garantit que la colonne 0 est bien Tranche_effectif_num
|
| 104 |
+
df_final = df[clean_features]
|
| 105 |
+
|
| 106 |
+
return xgb.DMatrix(df_final)
|