Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1040,46 +1040,48 @@ elif app_mode == "Model Training":
|
|
1040 |
use_grid_search = st.checkbox("Use Grid Search for Hyperparameter Tuning")
|
1041 |
|
1042 |
# In Model Training section - Fix indentation for training logic
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
|
1054 |
if model: # Only proceed if training was successful
|
1055 |
st.success("Model trained successfully!")
|
1056 |
-
# ... rest of model display code ...
|
1057 |
-
|
1058 |
-
# Display Metrics
|
1059 |
-
st.subheader("Model Evaluation Metrics")
|
1060 |
-
if problem_type in ["Classification", "Multiclass"]: #Combined here
|
1061 |
-
st.metric("Accuracy", f"{metrics['accuracy']:.2%}")
|
1062 |
-
|
1063 |
-
# Confusion Matrix Visualization
|
1064 |
-
st.subheader("Confusion Matrix")
|
1065 |
-
cm = metrics['confusion_matrix']
|
1066 |
-
class_names = [str(i) for i in np.unique(df[target])] #Get original class names
|
1067 |
-
fig_cm = px.imshow(cm,
|
1068 |
-
labels=dict(x="Predicted", y="Actual"),
|
1069 |
-
x=class_names,
|
1070 |
-
y=class_names,
|
1071 |
-
color_continuous_scale="Viridis")
|
1072 |
-
st.plotly_chart(fig_cm, use_container_width=True)
|
1073 |
-
|
1074 |
-
# Classification Report
|
1075 |
-
st.subheader("Classification Report")
|
1076 |
-
report = metrics['classification_report']
|
1077 |
-
report_df = pd.DataFrame(report).transpose()
|
1078 |
-
st.dataframe(report_df)
|
1079 |
|
1080 |
-
|
1081 |
-
|
1082 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1083 |
|
1084 |
# Feature Importance
|
1085 |
st.subheader("Feature Importance")
|
|
|
1040 |
use_grid_search = st.checkbox("Use Grid Search for Hyperparameter Tuning")
|
1041 |
|
1042 |
# In Model Training section - Fix indentation for training logic
|
1043 |
+
if st.button("Train Model"):
|
1044 |
+
if not features:
|
1045 |
+
st.error("Please select at least one feature.")
|
1046 |
+
st.stop()
|
1047 |
+
|
1048 |
+
# INDENT ALL THIS CODE UNDER THE BUTTON CLICK
|
1049 |
+
# Call the training function
|
1050 |
+
model, scaler, label_encoder, imputer_numerical, metrics, column_order, importance, X_train, y_train = train_model(
|
1051 |
+
df.copy(), target, features, problem_type, test_size, model_type, model_params, use_grid_search
|
1052 |
+
)
|
1053 |
|
1054 |
if model: # Only proceed if training was successful
|
1055 |
st.success("Model trained successfully!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1056 |
|
1057 |
+
# Display Metrics
|
1058 |
+
st.subheader("Model Evaluation Metrics")
|
1059 |
+
if problem_type in ["Classification", "Multiclass"]: # Combined here
|
1060 |
+
st.metric("Accuracy", f"{metrics['accuracy']:.2%}")
|
1061 |
+
|
1062 |
+
# Confusion Matrix Visualization
|
1063 |
+
st.subheader("Confusion Matrix")
|
1064 |
+
cm = metrics['confusion_matrix']
|
1065 |
+
class_names = [str(i) for i in np.unique(df[target])] # Get original class names
|
1066 |
+
fig_cm = px.imshow(cm,
|
1067 |
+
labels=dict(x="Predicted", y="Actual"),
|
1068 |
+
x=class_names,
|
1069 |
+
y=class_names,
|
1070 |
+
color_continuous_scale="Viridis")
|
1071 |
+
st.plotly_chart(fig_cm, use_container_width=True)
|
1072 |
+
|
1073 |
+
# Classification Report
|
1074 |
+
st.subheader("Classification Report")
|
1075 |
+
report = metrics['classification_report']
|
1076 |
+
report_df = pd.DataFrame(report).transpose()
|
1077 |
+
st.dataframe(report_df)
|
1078 |
+
|
1079 |
+
else:
|
1080 |
+
st.metric("MSE", f"{metrics['mse']:.2f}")
|
1081 |
+
st.metric("R2", f"{metrics['r2']:.2f}")
|
1082 |
+
|
1083 |
+
# Additional model display code...
|
1084 |
+
|
1085 |
|
1086 |
# Feature Importance
|
1087 |
st.subheader("Feature Importance")
|