Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,14 +59,22 @@ assert len(selected_features) == 138, f"Expected 138 features, got {len(selected
|
|
| 59 |
# ---------------------------------------------------------------------------
|
| 60 |
# LIME explainer
|
| 61 |
# Built ONCE at startup so explanations are reproducible across requests.
|
| 62 |
-
#
|
| 63 |
-
#
|
| 64 |
-
#
|
| 65 |
-
# (If you have a saved sample of real normalized training rows, swap it in
|
| 66 |
-
# here and explanations will reflect the true feature distribution.)
|
| 67 |
# ---------------------------------------------------------------------------
|
| 68 |
-
|
| 69 |
-
_lime_background =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
explainer = LimeTabularExplainer(
|
| 72 |
training_data=_lime_background,
|
|
|
|
| 59 |
# ---------------------------------------------------------------------------
|
| 60 |
# LIME explainer
|
| 61 |
# Built ONCE at startup so explanations are reproducible across requests.
|
| 62 |
+
# Prefers a real normalized training sample (lime_background.joblib). Falls
|
| 63 |
+
# back to seeded uniform noise if that file isn't present (still stable, but
|
| 64 |
+
# less faithful to the true feature distribution).
|
|
|
|
|
|
|
| 65 |
# ---------------------------------------------------------------------------
|
| 66 |
+
try:
|
| 67 |
+
_lime_background = joblib.load("lime_background.joblib")
|
| 68 |
+
if _lime_background.shape[1] != len(selected_features):
|
| 69 |
+
raise ValueError(
|
| 70 |
+
f"lime_background.joblib has {_lime_background.shape[1]} cols, "
|
| 71 |
+
f"expected {len(selected_features)}"
|
| 72 |
+
)
|
| 73 |
+
print(f"[LIME] Using real training sample: {_lime_background.shape}", flush=True)
|
| 74 |
+
except Exception as e:
|
| 75 |
+
print(f"[LIME] No usable lime_background.joblib ({e}); falling back to uniform noise.", flush=True)
|
| 76 |
+
_rng = np.random.default_rng(seed=42)
|
| 77 |
+
_lime_background = _rng.uniform(low=0.0, high=1.0, size=(500, len(selected_features)))
|
| 78 |
|
| 79 |
explainer = LimeTabularExplainer(
|
| 80 |
training_data=_lime_background,
|