Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -194,26 +194,36 @@ def predict_scores(df):
|
|
| 194 |
|
| 195 |
# List all models and exclude any FastAI learners (which can cause tabular DL issues)
|
| 196 |
try:
|
| 197 |
-
available_models = ag.model_names()
|
| 198 |
except Exception:
|
| 199 |
available_models = ag.model_names
|
| 200 |
safe_models = [m for m in available_models if "fastai" not in m.lower()]
|
| 201 |
print(f"[INFO] Using safe models: {safe_models}")
|
| 202 |
|
|
|
|
|
|
|
|
|
|
| 203 |
try:
|
| 204 |
-
|
|
|
|
| 205 |
if isinstance(proba, pd.DataFrame) and (1 in proba.columns):
|
| 206 |
return proba[1]
|
| 207 |
except Exception as e:
|
| 208 |
-
print("[WARN]
|
| 209 |
-
proba =
|
| 210 |
if isinstance(proba, pd.DataFrame) and (1 in proba.columns):
|
| 211 |
return proba[1]
|
| 212 |
|
| 213 |
-
# Fallback if
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 217 |
|
| 218 |
def pick_events(df,score,fps):
|
| 219 |
z=rolling_z(score,45); strong=(z>4.0); keep=strong.rolling(3,min_periods=1).sum()>=2
|
|
|
|
| 194 |
|
| 195 |
# List all models and exclude any FastAI learners (which can cause tabular DL issues)
|
| 196 |
try:
|
| 197 |
+
available_models = ag.model_names()
|
| 198 |
except Exception:
|
| 199 |
available_models = ag.model_names
|
| 200 |
safe_models = [m for m in available_models if "fastai" not in m.lower()]
|
| 201 |
print(f"[INFO] Using safe models: {safe_models}")
|
| 202 |
|
| 203 |
+
# Access AutoGluon's internal learner, which supports the `models` argument
|
| 204 |
+
learner = ag._learner
|
| 205 |
+
|
| 206 |
try:
|
| 207 |
+
# Get probabilities from the safe models only
|
| 208 |
+
proba = learner.predict_proba(X, models=safe_models)
|
| 209 |
if isinstance(proba, pd.DataFrame) and (1 in proba.columns):
|
| 210 |
return proba[1]
|
| 211 |
except Exception as e:
|
| 212 |
+
print("[WARN] FastAI submodel failed — retrying with safe models only:", e)
|
| 213 |
+
proba = learner.predict_proba(X, models=safe_models)
|
| 214 |
if isinstance(proba, pd.DataFrame) and (1 in proba.columns):
|
| 215 |
return proba[1]
|
| 216 |
|
| 217 |
+
# Fallback if probabilities aren’t available
|
| 218 |
+
try:
|
| 219 |
+
preds = learner.predict(X, models=safe_models)
|
| 220 |
+
s = pd.Series(preds).astype(float)
|
| 221 |
+
rng = (s.quantile(0.95) - s.quantile(0.05)) or 1.0
|
| 222 |
+
return ((s - s.quantile(0.05)) / rng).clip(0, 1)
|
| 223 |
+
except Exception as e:
|
| 224 |
+
print("[ERROR] Predictor fallback failed:", e)
|
| 225 |
+
return pd.Series(np.zeros(len(df)))
|
| 226 |
+
|
| 227 |
|
| 228 |
def pick_events(df,score,fps):
|
| 229 |
z=rolling_z(score,45); strong=(z>4.0); keep=strong.rolling(3,min_periods=1).sum()>=2
|