gdleds commited on
Commit
aed330f
·
1 Parent(s): 3083676
Files changed (1) hide show
  1. app.py +0 -115
app.py CHANGED
@@ -119,9 +119,6 @@ def load_raw_data() -> pd.DataFrame:
119
  )
120
  return pd.read_csv(url, sep=";")
121
 
122
- # ────────────────────────────────────────────────
123
- # 2) FONCTION D’ENTRAÎNEMENT + PRÉDICTIONS
124
- # ────────────────────────────────────────────────
125
 
126
  os.environ["MLFLOW_DEFAULT_ARTIFACT_ROOT"] = os.getenv("MLFLOW_DEFAULT_ARTIFACT_ROOT") # S3
127
  os.environ["AWS_ACCESS_KEY_ID"] = os.getenv("AWS_ACCESS_KEY_ID")
@@ -227,118 +224,6 @@ def train_model_and_predict(df_raw: pd.DataFrame) -> pd.DataFrame:
227
  df_map = df[["latitude", "longitude", "ville"] + list(horizons.values())].copy()
228
  return df_map
229
 
230
-
231
-
232
-
233
-
234
-
235
-
236
- # @st.cache_resource(show_spinner="⚙️ Entraînement du modèle…", ttl=None)
237
- # def train_model_and_predict(df_raw: pd.DataFrame) -> pd.DataFrame:
238
- # """Retourne df_map prêt pour la carte avec les colonnes
239
- # proba_7j, proba_30j, …, proba_180j."""
240
- # # a) Nettoyage
241
- # df = df_raw.copy()
242
- # df = df.rename(columns={"Feu prévu": "event", "décompte": "duration"})
243
- # df["event"] = df["event"].astype(bool)
244
- # df["duration"] = df["duration"].fillna(0)
245
-
246
- # # b) Features
247
- # features = [
248
- # "moyenne precipitations mois", "moyenne temperature mois",
249
- # "moyenne evapotranspiration mois", "moyenne vitesse vent année",
250
- # "moyenne vitesse vent mois", "moyenne temperature année",
251
- # "RR", "UM", "ETPMON", "TN", "TX", "Nombre de feu par an",
252
- # "Nombre de feu par mois", "jours_sans_pluie", "jours_TX_sup_30",
253
- # "ETPGRILLE_7j", "compteur jours vers prochain feu",
254
- # "compteur feu log", "Année", "Mois",
255
- # "moyenne precipitations année", "moyenne evapotranspiration année",
256
- # ]
257
- # features = [f for f in features if f in df.columns]
258
-
259
- # # c) split + Surv
260
- # y_struct = Surv.from_dataframe("event", "duration", df)
261
- # X_train, X_test, y_train, y_test = train_test_split(
262
- # df[features], y_struct, test_size=0.3, random_state=42
263
- # )
264
- # ev_train, du_train = y_train["event"], y_train["duration"]
265
- # ev_test, du_test = y_test["event"], y_test["duration"]
266
-
267
- # # d) Pipeline XGBSurv
268
- # pipe = Pipeline([
269
- # ("imputer", SimpleImputer(strategy="median")),
270
- # ("scaler", StandardScaler()),
271
- # ("xgb", XGBRegressor(
272
- # objective="survival:cox",
273
- # n_estimators=100,
274
- # learning_rate=0.05,
275
- # max_depth=3,
276
- # tree_method="hist",
277
- # random_state=42,
278
- # )),
279
- # ])
280
- # pipe.fit(X_train, du_train, xgb__sample_weight=ev_train)
281
-
282
- # # e) Affiche C-index dans la sidebar
283
- # log_hr_test = pipe.predict(X_test)
284
- # c_index = concordance_index_censored(ev_test, du_test, log_hr_test)[0]
285
- # st.sidebar.write(f"**C-index (test)** : {c_index:.3f}")
286
-
287
- # # f) Estimation du baseline hazard (Cox factice)
288
- # df_fake = pd.DataFrame({
289
- # "duration": du_train,
290
- # "event": ev_train,
291
- # "const": 1,
292
- # })
293
- # dmat = DMatrix(df_fake[["const"]])
294
- # dmat.set_float_info("label", df_fake["duration"])
295
- # dmat.set_float_info("label_lower_bound", df_fake["duration"])
296
- # dmat.set_float_info("label_upper_bound", df_fake["duration"])
297
- # dmat.set_float_info("weight", df_fake["event"])
298
- # bst_fake = xgb_train(
299
- # params={
300
- # "objective": "survival:cox",
301
- # "eval_metric": "cox-nloglik",
302
- # "learning_rate": 0.1,
303
- # "max_depth": 1,
304
- # "verbosity": 0,
305
- # },
306
- # dtrain=dmat,
307
- # num_boost_round=100,
308
- # )
309
- # log_hr_fake = bst_fake.predict(dmat)
310
-
311
- # df_risque = pd.DataFrame({
312
- # "duration": du_train,
313
- # "event": ev_train,
314
- # "log_risque": log_hr_fake + np.random.normal(0, 1e-4, size=len(log_hr_fake)),
315
- # })
316
- # cph = CoxPHFitter()
317
- # cph.fit(df_risque, duration_col="duration", event_col="event", show_progress=False)
318
-
319
- # baseline_cumhaz = cph.baseline_cumulative_hazard_
320
-
321
- # def S0(t: int) -> float:
322
- # """Survie de base S0(t) = exp(-H0(t))."""
323
- # idx = baseline_cumhaz.index
324
- # if t in idx:
325
- # H0 = baseline_cumhaz.loc[t].values[0]
326
- # else:
327
- # H0 = baseline_cumhaz.loc[idx[idx <= t]].iloc[-1, 0]
328
- # return float(np.exp(-H0))
329
-
330
- # horizons = {7: "proba_7j", 30: "proba_30j", 60: "proba_60j",
331
- # 90: "proba_90j", 180: "proba_180j"}
332
-
333
- # log_hr_all = pipe.predict(df[features])
334
- # HR = np.exp(log_hr_all)
335
-
336
- # for t, col in horizons.items():
337
- # df[col] = 1 - (S0(t) ** HR) # P(event ≤ t)
338
-
339
- # df_map = df[["latitude", "longitude", "ville"] + list(horizons.values())].copy()
340
- # return df_map
341
-
342
  # ─────────────────────────────────────────��──────
343
  # 3) AFFICHAGE SUR LA PAGE « Accueil »
344
  # ────────────────────────────────────────────────
 
119
  )
120
  return pd.read_csv(url, sep=";")
121
 
 
 
 
122
 
123
  os.environ["MLFLOW_DEFAULT_ARTIFACT_ROOT"] = os.getenv("MLFLOW_DEFAULT_ARTIFACT_ROOT") # S3
124
  os.environ["AWS_ACCESS_KEY_ID"] = os.getenv("AWS_ACCESS_KEY_ID")
 
224
  df_map = df[["latitude", "longitude", "ville"] + list(horizons.values())].copy()
225
  return df_map
226
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  # ─────────────────────────────────────────��──────
228
  # 3) AFFICHAGE SUR LA PAGE « Accueil »
229
  # ────────────────────────────────────────────────