Skip to content

Instantly share code, notes, and snippets.

@PranjalDureja0002
Created March 15, 2021 09:53
Show Gist options
  • Save PranjalDureja0002/328bea4e048cb59eac99a9c851ecbafb to your computer and use it in GitHub Desktop.
Save PranjalDureja0002/328bea4e048cb59eac99a9c851ecbafb to your computer and use it in GitHub Desktop.
model
from sklearn.metrics import roc_curve, auc
best_depth=dt_grid.best_params_['max_depth']
best_samples=dt_grid.best_params_['min_samples_split']
dt_1 = DecisionTreeClassifier(max_depth=best_depth,min_samples_split=best_samples)
dt_1.fit(X_train, y_train)
# roc_auc_score(y_true, y_score) the 2nd parameter should be probability estimates of the positive class
# not the predicted outputs
y_train_pred = pred_func(dt_1,X_train)
y_test_pred = pred_func(dt_1,X_test)
train_fpr, train_tpr, tr_thresholds = roc_curve(y_train, y_train_pred)
test_fpr, test_tpr, te_thresholds = roc_curve(y_test, y_test_pred)
plt.plot(train_fpr, train_tpr, label="Train AUC ="+str(auc(train_fpr, train_tpr)))
plt.plot(test_fpr, test_tpr, label="Test AUC ="+str(auc(test_fpr, test_tpr)))
plt.legend()
plt.xlabel("FPR")
plt.ylabel("TPR")
plt.title("AUC")
plt.grid()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment