Spaces:
Runtime error
Runtime error
danielritchie
commited on
Commit
•
100fe27
1
Parent(s):
16b217f
Update app.py
Browse files
app.py
CHANGED
@@ -41,12 +41,22 @@ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_
|
|
41 |
model = xgb.XGBClassifier()
|
42 |
model.fit(X_train, y_train)
|
43 |
|
44 |
-
# Function for making predictions
|
45 |
def predict(input_data):
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
prediction = model.predict(data)
|
48 |
return prediction[0]
|
49 |
|
|
|
50 |
# Set up Gradio interface for data exploration
|
51 |
def explore_data(row_number):
|
52 |
return df.iloc[row_number].to_dict()
|
|
|
41 |
model = xgb.XGBClassifier()
|
42 |
model.fit(X_train, y_train)
|
43 |
|
|
|
44 |
def predict(input_data):
|
45 |
+
# Remove features the user wants to omit (e.g., 'Gender')
|
46 |
+
for col in X.columns:
|
47 |
+
if input_data.get(col) is None:
|
48 |
+
input_data.pop(col, None)
|
49 |
+
|
50 |
+
# Keep only the features the user provided
|
51 |
+
data = pd.DataFrame([input_data], columns=input_data.keys())
|
52 |
+
|
53 |
+
# Align with model columns and fill missing required columns with defaults
|
54 |
+
data = data.reindex(columns=X.columns, fill_value=X.mean())
|
55 |
+
|
56 |
prediction = model.predict(data)
|
57 |
return prediction[0]
|
58 |
|
59 |
+
|
60 |
# Set up Gradio interface for data exploration
|
61 |
def explore_data(row_number):
|
62 |
return df.iloc[row_number].to_dict()
|