Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,7 +43,6 @@ def run_all_models(file):
|
|
43 |
return "Error processing file", None, None, None, None, None
|
44 |
|
45 |
try:
|
46 |
-
# Prepare data for models (assuming same feature set as training)
|
47 |
# Prepare data for models
|
48 |
model_features = df.copy()
|
49 |
for col in ['Id','anomaly_score','risk_flag']:
|
@@ -51,17 +50,16 @@ def run_all_models(file):
|
|
51 |
model_features.drop(col, axis=1, inplace=True)
|
52 |
# Fill NaNs
|
53 |
model_features = model_features.fillna(0)
|
54 |
-
|
55 |
# Align DataFrame columns to model’s training set:
|
56 |
model_features = model_features.reindex(
|
57 |
columns=expected_features, # from xgb_clf.get_booster().feature_names
|
58 |
fill_value=0
|
59 |
)
|
60 |
-
|
61 |
# 1. BANKRUPTCY CLASSIFICATION
|
62 |
-
bankruptcy_preds = xgb_clf.predict(
|
63 |
-
bankruptcy_probs = xgb_clf.predict_proba(
|
64 |
-
|
65 |
# Create bankruptcy visualization
|
66 |
fig1, ax1 = plt.subplots(figsize=(10, 6), facecolor='#1f1f1f')
|
67 |
ax1.set_facecolor('#1f1f1f')
|
@@ -91,7 +89,7 @@ def run_all_models(file):
|
|
91 |
plt.tight_layout()
|
92 |
|
93 |
# 2. ANOMALY DETECTION
|
94 |
-
anomaly_preds = xgb_reg.predict(
|
95 |
|
96 |
# Create anomaly visualization
|
97 |
fig2, ax2 = plt.subplots(figsize=(10, 6), facecolor='#1f1f1f')
|
|
|
43 |
return "Error processing file", None, None, None, None, None
|
44 |
|
45 |
try:
|
|
|
46 |
# Prepare data for models
|
47 |
model_features = df.copy()
|
48 |
for col in ['Id','anomaly_score','risk_flag']:
|
|
|
50 |
model_features.drop(col, axis=1, inplace=True)
|
51 |
# Fill NaNs
|
52 |
model_features = model_features.fillna(0)
|
53 |
+
|
54 |
# Align DataFrame columns to model’s training set:
|
55 |
model_features = model_features.reindex(
|
56 |
columns=expected_features, # from xgb_clf.get_booster().feature_names
|
57 |
fill_value=0
|
58 |
)
|
59 |
+
|
60 |
# 1. BANKRUPTCY CLASSIFICATION
|
61 |
+
bankruptcy_preds = xgb_clf.predict(clf_features)
|
62 |
+
bankruptcy_probs = xgb_clf.predict_proba(clf_features)
|
|
|
63 |
# Create bankruptcy visualization
|
64 |
fig1, ax1 = plt.subplots(figsize=(10, 6), facecolor='#1f1f1f')
|
65 |
ax1.set_facecolor('#1f1f1f')
|
|
|
89 |
plt.tight_layout()
|
90 |
|
91 |
# 2. ANOMALY DETECTION
|
92 |
+
anomaly_preds = xgb_reg.predict(reg_features)
|
93 |
|
94 |
# Create anomaly visualization
|
95 |
fig2, ax2 = plt.subplots(figsize=(10, 6), facecolor='#1f1f1f')
|