Skip to content

Commit

Permalink
Add package-mode=false and plot final ROC curve
Browse files Browse the repository at this point in the history
  • Loading branch information
brendancsmith committed Sep 21, 2024
1 parent 5f7f162 commit bfd95b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
19 changes: 15 additions & 4 deletions notebooks/exploratory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
"# ROC-AUC score\n",
"from sklearn.metrics import roc_auc_score, roc_curve\n",
"\n",
"y_scores = np.max(y_proba, axis=1)\n",
"y_scores = y_proba[:, 1]\n",
"\n",
"roc_auc = roc_auc_score(y_test, y_scores)\n",
"print(f\"ROC-AUC Score: {roc_auc:.4f}\")\n",
Expand Down Expand Up @@ -394,14 +394,15 @@
"source": [
"# Predict on test data\n",
"y_pred_best = xgb_clf_best.predict(X_test)\n",
"y_proba_best = xgb_clf_best.predict_proba(X_test)[:, 1]\n",
"y_proba_best = xgb_clf_best.predict_proba(X_test)\n",
"\n",
"# Accuracy\n",
"accuracy_best = accuracy_score(y_test, y_pred_best)\n",
"print(f\"Optimized Accuracy: {accuracy_best:.4f}\")\n",
"\n",
"# ROC-AUC score\n",
"roc_auc_best = roc_auc_score(y_test, y_proba_best)\n",
"y_scores_best = y_proba_best[:, 1]\n",
"roc_auc_best = roc_auc_score(y_test, y_scores_best)\n",
"print(f\"Optimized ROC-AUC Score: {roc_auc_best:.4f}\")"
]
},
Expand All @@ -410,7 +411,17 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"# Plot ROC curve\n",
"fpr_best, tpr_best, thresholds_best = roc_curve(y_test, y_scores_best)\n",
"plt.plot(fpr_best, tpr_best, label=f\"AUC = {roc_auc_best:.4f}\")\n",
"plt.plot([0, 1], [0, 1], linestyle=\"--\")\n",
"plt.xlabel(\"False Positive Rate\")\n",
"plt.ylabel(\"True Positive Rate\")\n",
"plt.title(\"ROC Curve\")\n",
"plt.legend()\n",
"plt.show()"
]
}
],
"metadata": {
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tool.poetry]
package-mode = false
name = "credit-risk-modeling"
version = "0.1.0"
description = "Credit Risk Modeling using XGBoost"
Expand Down

0 comments on commit bfd95b7

Please sign in to comment.