Spaces:
Sleeping
Sleeping
Updated app.py
Browse files
app.py
CHANGED
|
@@ -54,6 +54,31 @@ def evaluate_models(models, X_test, y_test):
|
|
| 54 |
def main():
|
| 55 |
st.title("Model Performance and Predictions")
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Load and split data
|
| 58 |
X, y = load_data()
|
| 59 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
@@ -110,30 +135,5 @@ def main():
|
|
| 110 |
ax.set_title(f'Feature Importance - {selected_model_name}')
|
| 111 |
st.pyplot(fig)
|
| 112 |
|
| 113 |
-
st.subheader("Make Predictions")
|
| 114 |
-
input_data = st.text_input("Enter features separated by commas (e.g., 0.1, 0.2, ..., 0.5)")
|
| 115 |
-
if input_data:
|
| 116 |
-
try:
|
| 117 |
-
# Convert input data to numpy array and reshape
|
| 118 |
-
input_features = np.array([float(i) for i in input_data.split(',')]).reshape(1, -1)
|
| 119 |
-
|
| 120 |
-
# Check if the number of features matches the model's input
|
| 121 |
-
if input_features.shape[1] != X_train_scaled.shape[1]:
|
| 122 |
-
st.error(f"Number of features should be {X_train_scaled.shape[1]}.")
|
| 123 |
-
else:
|
| 124 |
-
# Transform input features using the same scaler
|
| 125 |
-
input_features_scaled = scaler.transform(input_features)
|
| 126 |
-
|
| 127 |
-
# Predict using the selected model
|
| 128 |
-
prediction = selected_model.predict(input_features_scaled)
|
| 129 |
-
prediction_proba = selected_model.predict_proba(input_features_scaled)[:, 1]
|
| 130 |
-
st.write(f"Prediction: {'Positive' if prediction[0] == 1 else 'Negative'}")
|
| 131 |
-
st.write(f"Probability of Positive: {prediction_proba[0]:.4f}")
|
| 132 |
-
|
| 133 |
-
except ValueError:
|
| 134 |
-
st.error("Please enter valid numerical values separated by commas.")
|
| 135 |
-
except Exception as e:
|
| 136 |
-
st.error(f"An error occurred: {e}")
|
| 137 |
-
|
| 138 |
if __name__ == "__main__":
|
| 139 |
main()
|
|
|
|
| 54 |
def main():
|
| 55 |
st.title("Model Performance and Predictions")
|
| 56 |
|
| 57 |
+
st.subheader("Make Predictions")
|
| 58 |
+
input_data = st.text_input("Enter features separated by commas (e.g., 0.1, 0.2, ..., 0.5)")
|
| 59 |
+
if input_data:
|
| 60 |
+
try:
|
| 61 |
+
# Convert input data to numpy array and reshape
|
| 62 |
+
input_features = np.array([float(i) for i in input_data.split(',')]).reshape(1, -1)
|
| 63 |
+
|
| 64 |
+
# Check if the number of features matches the model's input
|
| 65 |
+
if input_features.shape[1] != X_train_scaled.shape[1]:
|
| 66 |
+
st.error(f"Number of features should be {X_train_scaled.shape[1]}.")
|
| 67 |
+
else:
|
| 68 |
+
# Transform input features using the same scaler
|
| 69 |
+
input_features_scaled = scaler.transform(input_features)
|
| 70 |
+
|
| 71 |
+
# Predict using the selected model
|
| 72 |
+
prediction = selected_model.predict(input_features_scaled)
|
| 73 |
+
prediction_proba = selected_model.predict_proba(input_features_scaled)[:, 1]
|
| 74 |
+
st.write(f"Prediction: {'Positive' if prediction[0] == 1 else 'Negative'}")
|
| 75 |
+
st.write(f"Probability of Positive: {prediction_proba[0]:.4f}")
|
| 76 |
+
|
| 77 |
+
except ValueError:
|
| 78 |
+
st.error("Please enter valid numerical values separated by commas.")
|
| 79 |
+
except Exception as e:
|
| 80 |
+
st.error(f"An error occurred: {e}")
|
| 81 |
+
|
| 82 |
# Load and split data
|
| 83 |
X, y = load_data()
|
| 84 |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
|
|
|
| 135 |
ax.set_title(f'Feature Importance - {selected_model_name}')
|
| 136 |
st.pyplot(fig)
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
if __name__ == "__main__":
|
| 139 |
main()
|