Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,13 +6,13 @@ import matplotlib.pyplot as plt
|
|
| 6 |
from sklearn.model_selection import train_test_split
|
| 7 |
from sklearn.impute import SimpleImputer
|
| 8 |
from sklearn.preprocessing import LabelEncoder, StandardScaler
|
| 9 |
-
from sklearn.ensemble import RandomForestClassifier
|
| 10 |
-
from sklearn.linear_model import LogisticRegression
|
| 11 |
-
from sklearn.svm import SVC
|
| 12 |
-
from sklearn.neighbors import KNeighborsClassifier
|
| 13 |
-
from sklearn.tree import DecisionTreeClassifier
|
| 14 |
from sklearn.naive_bayes import GaussianNB
|
| 15 |
-
from sklearn.metrics import
|
| 16 |
from scipy import stats
|
| 17 |
|
| 18 |
# File uploader
|
|
@@ -90,7 +90,7 @@ if uploaded_file is not None:
|
|
| 90 |
# Store results in a dictionary
|
| 91 |
results = []
|
| 92 |
|
| 93 |
-
# Model Selection and Evaluation
|
| 94 |
if is_classification:
|
| 95 |
model_choices = [
|
| 96 |
("Random Forest", RandomForestClassifier(n_estimators=50)),
|
|
@@ -105,32 +105,18 @@ if uploaded_file is not None:
|
|
| 105 |
model.fit(X_train, y_train)
|
| 106 |
y_pred = model.predict(X_test)
|
| 107 |
accuracy = accuracy_score(y_test, y_pred)
|
| 108 |
-
results.append([name, accuracy
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
("K-Nearest Neighbors", KNeighborsRegressor(n_neighbors=5)),
|
| 116 |
-
("Decision Tree", DecisionTreeRegressor()),
|
| 117 |
-
("Ridge Regression", Ridge())
|
| 118 |
-
]
|
| 119 |
-
|
| 120 |
-
for name, model in model_choices:
|
| 121 |
-
model.fit(X_train, y_train)
|
| 122 |
-
y_pred = model.predict(X_test)
|
| 123 |
-
mse = mean_squared_error(y_test, y_pred)
|
| 124 |
-
results.append([name, None, mse])
|
| 125 |
-
|
| 126 |
-
# Display results in a table
|
| 127 |
-
st.subheader("Model Performance Results")
|
| 128 |
-
results_df = pd.DataFrame(results, columns=["Model", "Accuracy" if is_classification else "Accuracy (N/A)", "Mean Squared Error" if not is_classification else "MSE (N/A)"])
|
| 129 |
-
|
| 130 |
-
# Bold the headers
|
| 131 |
-
st.markdown(f"**Model Performance Results**")
|
| 132 |
-
st.dataframe(results_df)
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
# Option to download the model performance metrics (Results Table)
|
| 135 |
st.download_button(
|
| 136 |
label="Download Model Report",
|
|
|
|
| 6 |
from sklearn.model_selection import train_test_split
|
| 7 |
from sklearn.impute import SimpleImputer
|
| 8 |
from sklearn.preprocessing import LabelEncoder, StandardScaler
|
| 9 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 10 |
+
from sklearn.linear_model import LogisticRegression
|
| 11 |
+
from sklearn.svm import SVC
|
| 12 |
+
from sklearn.neighbors import KNeighborsClassifier
|
| 13 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 14 |
from sklearn.naive_bayes import GaussianNB
|
| 15 |
+
from sklearn.metrics import accuracy_score, classification_report
|
| 16 |
from scipy import stats
|
| 17 |
|
| 18 |
# File uploader
|
|
|
|
| 90 |
# Store results in a dictionary
|
| 91 |
results = []
|
| 92 |
|
| 93 |
+
# Model Selection and Evaluation (For Classification)
|
| 94 |
if is_classification:
|
| 95 |
model_choices = [
|
| 96 |
("Random Forest", RandomForestClassifier(n_estimators=50)),
|
|
|
|
| 105 |
model.fit(X_train, y_train)
|
| 106 |
y_pred = model.predict(X_test)
|
| 107 |
accuracy = accuracy_score(y_test, y_pred)
|
| 108 |
+
results.append([name, accuracy])
|
| 109 |
|
| 110 |
+
# Display results in a table
|
| 111 |
+
st.subheader("Model Performance Results")
|
| 112 |
+
results_df = pd.DataFrame(results, columns=["Model", "Accuracy"])
|
| 113 |
+
st.markdown(f"**Model Performance Results**")
|
| 114 |
+
st.dataframe(results_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
# If it's not classification (i.e., regression)
|
| 117 |
+
else:
|
| 118 |
+
st.warning("Regression models are not implemented in this version. Please select a classification target.")
|
| 119 |
+
|
| 120 |
# Option to download the model performance metrics (Results Table)
|
| 121 |
st.download_button(
|
| 122 |
label="Download Model Report",
|