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

fix: update confusion matrix and score distribution functions to load pre-computed CV predictions

Browse files
app/training/generate_paper_figures.py CHANGED
@@ -164,9 +164,9 @@ def plot_roc_curves(ml: dict, dl: dict) -> None:
164
  def plot_confusion_matrix_lightgbm(ml: dict) -> None:
165
  name = "LightGBM"
166
  data = ml[name]
167
- y_true = np.array(data["y_true"])
168
- y_prob = np.array(data["y_prob"])
169
- # Use Youden's J threshold if stored, else 0.5
170
  threshold = data.get("optimal_threshold", 0.5)
171
  y_pred = (y_prob >= threshold).astype(int)
172
 
@@ -496,12 +496,13 @@ def plot_feature_importance(ml: dict) -> None:
496
  def plot_score_distribution(ml: dict) -> None:
497
  best = ml.get("_best_model", "LightGBM")
498
  data = ml.get(best, {})
499
- if not data or "y_true" not in data:
500
- print(" ⚠ No score distribution data")
 
 
501
  return
502
-
503
- y_true = np.array(data["y_true"])
504
- y_prob = np.array(data["y_prob"])
505
  threshold = data.get("optimal_threshold", 0.5)
506
 
507
  fig, ax = plt.subplots(figsize=(7, 4.5))
 
164
  def plot_confusion_matrix_lightgbm(ml: dict) -> None:
165
  name = "LightGBM"
166
  data = ml[name]
167
+ # Load pre-computed CV predictions
168
+ y_true = np.load(MODELS / "lgbm_cv_ytrue.npy")
169
+ y_prob = np.load(MODELS / "lgbm_cv_probs.npy")
170
  threshold = data.get("optimal_threshold", 0.5)
171
  y_pred = (y_prob >= threshold).astype(int)
172
 
 
496
  def plot_score_distribution(ml: dict) -> None:
497
  best = ml.get("_best_model", "LightGBM")
498
  data = ml.get(best, {})
499
+ y_prob_path = MODELS / "lgbm_cv_probs.npy"
500
+ y_true_path = MODELS / "lgbm_cv_ytrue.npy"
501
+ if not y_prob_path.exists():
502
+ print(" SKIP No score distribution data")
503
  return
504
+ y_true = np.load(y_true_path)
505
+ y_prob = np.load(y_prob_path)
 
506
  threshold = data.get("optimal_threshold", 0.5)
507
 
508
  fig, ax = plt.subplots(figsize=(7, 4.5))