JonnyBP commited on
Commit
7bbb616
Β·
1 Parent(s): 6cda091

test isolated pipeline outputs and evaluator summary append

Browse files
src/evaluation/evaluator.py CHANGED
@@ -228,19 +228,41 @@ class Evaluator:
228
 
229
  def save_summary(self, all_metrics: list[dict], path: str | Path = None) -> Path:
230
  """
231
- Guarda un CSV con todos los experimentos para comparar.
232
- Este es el 'reports/summary.csv' que mencionaba el roadmap.
233
  """
 
234
  path = Path(path or self.output_dir / "summary.csv")
235
- df = pd.DataFrame(all_metrics)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
  # Ordenar por F1 descendente
238
  if "f1_weighted" in df.columns:
239
  df = df.sort_values("f1_weighted", ascending=False)
240
 
 
241
  df.to_csv(path, index=False)
242
- logger.info(f"Summary guardado: {path}")
243
- print(df[["model", "f1_weighted", "roc_auc", "fp", "fn"]].to_string(index=False))
 
 
 
 
244
  return path
245
 
246
  # ── Interno ──────────────────────────────────────────────────────────────
 
228
 
229
  def save_summary(self, all_metrics: list[dict], path: str | Path = None) -> Path:
230
  """
231
+ Guarda un CSV acumulativo con todos los experimentos.
232
+ Si summary.csv ya existe, agrega nuevas filas.
233
  """
234
+
235
  path = Path(path or self.output_dir / "summary.csv")
236
+
237
+ # Nuevo dataframe
238
+ new_df = pd.DataFrame(all_metrics)
239
+
240
+ # Si ya existe un summary anterior β†’ cargarlo
241
+ if path.exists():
242
+ old_df = pd.read_csv(path)
243
+
244
+ # Concatenar viejo + nuevo
245
+ df = pd.concat([old_df, new_df], ignore_index=True)
246
+
247
+ # Evitar duplicados por run_id si existe
248
+ if "run_id" in df.columns:
249
+ df = df.drop_duplicates(subset=["run_id"], keep="last")
250
+
251
+ else:
252
+ df = new_df
253
 
254
  # Ordenar por F1 descendente
255
  if "f1_weighted" in df.columns:
256
  df = df.sort_values("f1_weighted", ascending=False)
257
 
258
+ # Guardar actualizado
259
  df.to_csv(path, index=False)
260
+
261
+ logger.info(f"Summary actualizado: {path}")
262
+
263
+ cols = [c for c in ["model", "f1_weighted", "roc_auc", "fp", "fn"] if c in df.columns]
264
+ print(df[cols].to_string(index=False))
265
+
266
  return path
267
 
268
  # ── Interno ──────────────────────────────────────────────────────────────
src/pipeline/run_pipeline.py CHANGED
@@ -161,6 +161,8 @@ def run_pipeline(model_type: str = "lr") -> dict:
161
  metrics["run_id"] = run_id
162
  metrics["model_path"]= str(model_path)
163
  evaluator.save_report(metrics, f"exp_{run_id}_{model_type}")
 
 
164
  evaluator.save_summary([metrics])
165
 
166
  logger.info("=" * 60)
 
161
  metrics["run_id"] = run_id
162
  metrics["model_path"]= str(model_path)
163
  evaluator.save_report(metrics, f"exp_{run_id}_{model_type}")
164
+ metrics["model_type"] = model_type
165
+ metrics["run_id"] = run_id
166
  evaluator.save_summary([metrics])
167
 
168
  logger.info("=" * 60)