Update my_pages/multiverse.py
Browse files- my_pages/multiverse.py +35 -21
my_pages/multiverse.py
CHANGED
|
@@ -249,31 +249,45 @@ def render():
|
|
| 249 |
|
| 250 |
return split_and_scale(features, label, test_split, preprocess_scale)
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
|
|
|
|
|
|
|
|
|
| 253 |
### Main Code Starts Here
|
| 254 |
scaler, feature_sel, arch, seed = selected_path[0], selected_path[1], selected_path[2], int(selected_path[3])
|
| 255 |
-
X_train, X_test, y_train, y_test = get_stackoverflow_dataset(preprocess_scale=scaler)
|
| 256 |
-
|
| 257 |
-
if feature_sel=="Select K Best (k=5)":
|
| 258 |
-
selector = SelectKBest(score_func=f_classif, k=5)
|
| 259 |
-
X_train = selector.fit_transform(X_train, y_train)
|
| 260 |
-
X_test = selector.transform(X_test)
|
| 261 |
-
elif feature_sel=="PCA (n=5)":
|
| 262 |
-
pca = PCA(n_components=2)
|
| 263 |
-
X_train = pca.fit_transform(X_train, y_train)
|
| 264 |
-
X_test = pca.transform(X_test)
|
| 265 |
-
|
| 266 |
-
placeholder = st.empty()
|
| 267 |
-
modelclass_dict = {'Neural Network (Small)': MLPClassifier([10], random_state=seed, max_iter=500),
|
| 268 |
-
'Logistic Regression': SGDClassifier(random_state=seed, max_iter=500),
|
| 269 |
-
'Decision Tree': DecisionTreeClassifier(random_state=seed)}
|
| 270 |
-
model = modelclass_dict[arch]
|
| 271 |
-
placeholder.write("Training your model.")
|
| 272 |
-
model.fit(X_train, y_train)
|
| 273 |
-
placeholder.empty()
|
| 274 |
-
|
| 275 |
-
y_pred = model.predict(X_test)
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
uniq_perc = 10.5
|
| 278 |
add_red_text(f"""
|
| 279 |
<b>Multiplicity of your predictions:</b> Your chosen model rejected {uniq_perc}% loans that would have been accepted by more than 90% of the other models.<br><br>
|
|
|
|
| 249 |
|
| 250 |
return split_and_scale(features, label, test_split, preprocess_scale)
|
| 251 |
|
| 252 |
+
def model_train_and_pred(scaler, feature_sel, arch, seed):
|
| 253 |
+
X_train, X_test, y_train, y_test = get_stackoverflow_dataset(preprocess_scale=scaler)
|
| 254 |
+
|
| 255 |
+
if feature_sel=="Select K Best (k=5)":
|
| 256 |
+
selector = SelectKBest(score_func=f_classif, k=5)
|
| 257 |
+
X_train = selector.fit_transform(X_train, y_train)
|
| 258 |
+
X_test = selector.transform(X_test)
|
| 259 |
+
elif feature_sel=="PCA (n=5)":
|
| 260 |
+
pca = PCA(n_components=2)
|
| 261 |
+
X_train = pca.fit_transform(X_train, y_train)
|
| 262 |
+
X_test = pca.transform(X_test)
|
| 263 |
+
|
| 264 |
+
modelclass_dict = {'Neural Network (Small)': MLPClassifier([10], random_state=seed, max_iter=500),
|
| 265 |
+
'Logistic Regression': SGDClassifier(random_state=seed, max_iter=500),
|
| 266 |
+
'Decision Tree': DecisionTreeClassifier(random_state=seed)}
|
| 267 |
+
model = modelclass_dict[arch]
|
| 268 |
+
model.fit(X_train, y_train)
|
| 269 |
|
| 270 |
+
y_pred = model.predict(X_test)
|
| 271 |
+
return y_pred
|
| 272 |
+
|
| 273 |
### Main Code Starts Here
|
| 274 |
scaler, feature_sel, arch, seed = selected_path[0], selected_path[1], selected_path[2], int(selected_path[3])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
+
all_preds = []
|
| 277 |
+
for scaler in choices_list[0]["options"]:
|
| 278 |
+
for feature_sel in choices_list[1]["options"]:
|
| 279 |
+
for arch in choices_list[2]["options"]:
|
| 280 |
+
for seed in choices_list[3]["options"]:
|
| 281 |
+
seed = int(seed)
|
| 282 |
+
y_pred_local = model_train_and_pred(scaler, feature_sel, arch, seed)
|
| 283 |
+
all_preds.append(y_pred_local)
|
| 284 |
+
st.markdown(scaler + feature_sel + arch)
|
| 285 |
+
all_preds_numpy = np.array(all_preds)
|
| 286 |
+
np.save("all_predictions.npy", all_preds_numpy)
|
| 287 |
+
|
| 288 |
+
all_preds_numpy = np.array(all_preds)
|
| 289 |
+
np.save("all_predictions.npy", all_preds_numpy)
|
| 290 |
+
|
| 291 |
uniq_perc = 10.5
|
| 292 |
add_red_text(f"""
|
| 293 |
<b>Multiplicity of your predictions:</b> Your chosen model rejected {uniq_perc}% loans that would have been accepted by more than 90% of the other models.<br><br>
|