AbdullahImran commited on
Commit
0697066
·
verified ·
1 Parent(s): 09392c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -42,22 +42,20 @@ def run_all_models(file):
42
 
43
  try:
44
  # Prepare data for models (assuming same feature set as training)
 
45
  model_features = df.copy()
46
-
47
- # Remove non-feature columns if they exist
48
- cols_to_remove = ['Id', 'anomaly_score', 'risk_flag']
49
- for col in cols_to_remove:
50
- if col in model_features.columns:
51
- model_features = model_features.drop(col, axis=1)
52
-
53
- # Handle missing values
54
  model_features = model_features.fillna(0)
55
-
56
- for col in model_features.select_dtypes(include=['object']).columns:
57
- model_features[col] = model_features[col].astype(str)
58
- model_features[col] = model_features[col].fillna("Unknown")
59
- model_features[col] = model_features[col].astype("category").cat.codes
60
-
 
61
  # 1. BANKRUPTCY CLASSIFICATION
62
  bankruptcy_preds = xgb_clf.predict(model_features)
63
  bankruptcy_probs = xgb_clf.predict_proba(model_features)
 
42
 
43
  try:
44
  # Prepare data for models (assuming same feature set as training)
45
+ # Prepare data for models
46
  model_features = df.copy()
47
+ for col in ['Id','anomaly_score','risk_flag']:
48
+ if col in model_features:
49
+ model_features.drop(col, axis=1, inplace=True)
50
+ # Fill NaNs
 
 
 
 
51
  model_features = model_features.fillna(0)
52
+
53
+ # Align DataFrame columns to model’s training set:
54
+ model_features = model_features.reindex(
55
+ columns=expected_features, # from xgb_clf.get_booster().feature_names
56
+ fill_value=0
57
+ )
58
+
59
  # 1. BANKRUPTCY CLASSIFICATION
60
  bankruptcy_preds = xgb_clf.predict(model_features)
61
  bankruptcy_probs = xgb_clf.predict_proba(model_features)