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 accuracy_score, classification_report
|
| 16 |
from scipy import stats
|
| 17 |
|
| 18 |
# File uploader
|
|
@@ -77,7 +77,7 @@ if uploaded_file is not None:
|
|
| 77 |
y = df_cleaned[target]
|
| 78 |
|
| 79 |
# Determine if the target is continuous or categorical
|
| 80 |
-
is_classification = len(y.unique()) <= 10 # If target
|
| 81 |
|
| 82 |
# Ensure there is enough data before proceeding with train-test split
|
| 83 |
if len(X) == 0 or len(y) == 0:
|
|
@@ -113,9 +113,27 @@ if uploaded_file is not None:
|
|
| 113 |
st.markdown(f"**Model Performance Results**")
|
| 114 |
st.dataframe(results_df)
|
| 115 |
|
| 116 |
-
#
|
| 117 |
else:
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
# Option to download the model performance metrics (Results Table)
|
| 121 |
st.download_button(
|
|
|
|
| 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, RandomForestRegressor
|
| 10 |
+
from sklearn.linear_model import LogisticRegression, LinearRegression
|
| 11 |
+
from sklearn.svm import SVC, SVR
|
| 12 |
+
from sklearn.neighbors import KNeighborsClassifier, KNeighborsRegressor
|
| 13 |
+
from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
|
| 14 |
from sklearn.naive_bayes import GaussianNB
|
| 15 |
+
from sklearn.metrics import accuracy_score, mean_squared_error, classification_report
|
| 16 |
from scipy import stats
|
| 17 |
|
| 18 |
# File uploader
|
|
|
|
| 77 |
y = df_cleaned[target]
|
| 78 |
|
| 79 |
# Determine if the target is continuous or categorical
|
| 80 |
+
is_classification = y.dtype == 'object' or len(y.unique()) <= 10 # If target is categorical or has few unique values, treat as classification
|
| 81 |
|
| 82 |
# Ensure there is enough data before proceeding with train-test split
|
| 83 |
if len(X) == 0 or len(y) == 0:
|
|
|
|
| 113 |
st.markdown(f"**Model Performance Results**")
|
| 114 |
st.dataframe(results_df)
|
| 115 |
|
| 116 |
+
# For Regression
|
| 117 |
else:
|
| 118 |
+
model_choices = [
|
| 119 |
+
("Random Forest", RandomForestRegressor(n_estimators=50)),
|
| 120 |
+
("Linear Regression", LinearRegression()),
|
| 121 |
+
("SVR", SVR()),
|
| 122 |
+
("K-Nearest Neighbors", KNeighborsRegressor(n_neighbors=5)),
|
| 123 |
+
("Decision Tree", DecisionTreeRegressor()),
|
| 124 |
+
]
|
| 125 |
+
|
| 126 |
+
for name, model in model_choices:
|
| 127 |
+
model.fit(X_train, y_train)
|
| 128 |
+
y_pred = model.predict(X_test)
|
| 129 |
+
mse = mean_squared_error(y_test, y_pred)
|
| 130 |
+
results.append([name, mse])
|
| 131 |
+
|
| 132 |
+
# Display results in a table
|
| 133 |
+
st.subheader("Model Performance Results")
|
| 134 |
+
results_df = pd.DataFrame(results, columns=["Model", "Mean Squared Error"])
|
| 135 |
+
st.markdown(f"**Model Performance Results**")
|
| 136 |
+
st.dataframe(results_df)
|
| 137 |
|
| 138 |
# Option to download the model performance metrics (Results Table)
|
| 139 |
st.download_button(
|