Skip to content

Instantly share code, notes, and snippets.

@eugeneyan
Created February 21, 2021 19:09
Show Gist options
  • Save eugeneyan/efde4f7905d09bbead33685d60b01014 to your computer and use it in GitHub Desktop.
Save eugeneyan/efde4f7905d09bbead33685d60b01014 to your computer and use it in GitHub Desktop.
Test Tree depth leads to increased accuracy
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