Rthur2003 commited on
Commit
129f521
·
1 Parent(s): fa18330

fix: update calibration and precision-recall plotting functions to load data from files

Browse files
app/training/generate_paper_figures.py CHANGED
@@ -530,11 +530,14 @@ def plot_score_distribution(ml: dict) -> None:
530
  def plot_calibration(ml: dict) -> None:
531
  best = ml.get("_best_model", "LightGBM")
532
  data = ml.get(best, {})
533
- if not data or "y_true" not in data:
 
 
 
534
  return
535
 
536
- y_true = np.array(data["y_true"])
537
- y_prob = np.array(data["y_prob"])
538
 
539
  from sklearn.metrics import brier_score_loss
540
  brier = brier_score_loss(y_true, y_prob)
@@ -568,12 +571,14 @@ def plot_calibration(ml: dict) -> None:
568
 
569
  def plot_precision_recall(ml: dict) -> None:
570
  best = ml.get("_best_model", "LightGBM")
571
- data = ml.get(best, {})
572
- if not data or "y_true" not in data:
 
 
573
  return
574
 
575
- y_true = np.array(data["y_true"])
576
- y_prob = np.array(data["y_prob"])
577
  prec, rec, _ = precision_recall_curve(y_true, y_prob)
578
  ap = average_precision_score(y_true, y_prob)
579
  baseline = y_true.mean()
 
530
  def plot_calibration(ml: dict) -> None:
531
  best = ml.get("_best_model", "LightGBM")
532
  data = ml.get(best, {})
533
+ y_prob_path = MODELS / "lgbm_cv_probs.npy"
534
+ y_true_path = MODELS / "lgbm_cv_ytrue.npy"
535
+ if not y_prob_path.exists():
536
+ print(" SKIP No calibration data")
537
  return
538
 
539
+ y_true = np.load(y_true_path)
540
+ y_prob = np.load(y_prob_path)
541
 
542
  from sklearn.metrics import brier_score_loss
543
  brier = brier_score_loss(y_true, y_prob)
 
571
 
572
  def plot_precision_recall(ml: dict) -> None:
573
  best = ml.get("_best_model", "LightGBM")
574
+ y_prob_path = MODELS / "lgbm_cv_probs.npy"
575
+ y_true_path = MODELS / "lgbm_cv_ytrue.npy"
576
+ if not y_prob_path.exists():
577
+ print(" SKIP No precision-recall data")
578
  return
579
 
580
+ y_true = np.load(y_true_path)
581
+ y_prob = np.load(y_prob_path)
582
  prec, rec, _ = precision_recall_curve(y_true, y_prob)
583
  ap = average_precision_score(y_true, y_prob)
584
  baseline = y_true.mean()