Created
February 21, 2021 19:09
-
-
Save eugeneyan/efde4f7905d09bbead33685d60b01014 to your computer and use it in GitHub Desktop.
Test Tree depth leads to increased accuracy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def test_dt_increase_acc(dummy_titanic): | |
X_train, y_train, _, _ = dummy_titanic | |
acc_list = [] | |
auc_list = [] | |
for depth in range(1, 10): | |
dt = DecisionTree(depth_limit=depth) | |
dt.fit(X_train, y_train) | |
pred = dt.predict(X_train) | |
pred_binary = np.round(pred) | |
acc_list.append(accuracy_score(y_train, pred_binary)) | |
auc_list.append(roc_auc_score(y_train, pred)) | |
assert sorted(acc_list) == acc_list, 'Accuracy should increase as tree depth increases.' | |
assert sorted(auc_list) == auc_list, 'AUC ROC should increase as tree depth increases.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment