0
$\begingroup$

I am a student working on building a predictive model. While evaluating different models, I noticed that in some cases, some AUC is around 0.75, but the ROC curve appears below the random guess line. I am unsure why this is happening.

My target variable is binary (0 or 1), and my dataset consists of 42 patients. I would appreciate any insights or explanations for this issue.

Looking forward to your help!

This is my code:

for name, model in best_models.items(): # ✅ Extract probability estimates if hasattr(model, "predict_proba"): y_prob = model.predict_proba(X_test)[:, 1] # Get class 1 probability elif hasattr(model, "decision_function"): raw_scores = model.decision_function(X_test) y_prob = softmax(raw_scores)[:, 1] # Convert raw scores to probabilities else: continue # Skip models that don't provide probability estimates # ✅ Compute ROC curve & AUC fpr, tpr, _ = roc_curve(y_test, y_prob) auc_score = auc(fpr, tpr) # ✅ Fix flipped AUC values (if needed) if auc_score < 0.5: y_prob = 1 - y_prob # Flip probability assignments fpr, tpr, _ = roc_curve(y_test, y_prob) auc_score = auc(fpr, tpr) # ✅ Ensure FPR values are strictly increasing unique_fpr, unique_indices = np.unique(fpr, return_index=True) unique_tpr = tpr[unique_indices] # ✅ Smooth the ROC curve smooth_fpr = np.linspace(0, 1, 300) interpolator = PchipInterpolator(unique_fpr, unique_tpr) smooth_tpr = interpolator(smooth_fpr) # ✅ Plot the ROC curve plt.figure(figsize=(7, 5)) plt.plot(smooth_fpr, smooth_tpr, label=f"{name} (AUC = {auc_score:.2f})", linewidth=2, color="blue") plt.plot([0, 1], [0, 1], linestyle="--", color="gray", label="Random Guess (AUC = 0.50)") plt.plot([0, 0, 1], [0, 1, 1], linestyle="dashed", color="purple", label="Perfect Classifier") # ✅ Configure plot aesthetics plt.xlabel("False Positive Rate (FPR)") plt.ylabel("True Positive Rate (TPR)") plt.title(f"Smooth ROC Curve for {name}") plt.legend(loc="lower right") plt.grid(True) # ✅ Show the plot plt.show() 

ROC-AUC

$\endgroup$
7
  • $\begingroup$ You get the same plot if you remove the decision_function, the flipped AUC and the interpolation parts ? $\endgroup$ Commented Feb 18 at 12:28
  • $\begingroup$ Rehaqds, Thank you do much for your response. I removed them and then i got step-like curve, i would like to get a curvy style but dont know how, thats why i used them earlier. $\endgroup$ Commented Feb 18 at 17:06
  • $\begingroup$ The aesthetic should be easy to solve, I asked the question to know if after that the plot looks like what could be expected of a AUC=0.75 unlike the plot in your question. $\endgroup$ Commented Feb 18 at 19:59
  • $\begingroup$ Moreover a ROC curve with steps is not unusual as you can see there: scikit-learn.org/stable/auto_examples/miscellaneous/… . On the page you will also notice RocCurveDisplay.from_estimator() which make it easy to draw a ROC curve. $\endgroup$ Commented Feb 18 at 20:07
  • $\begingroup$ So now i have 3 roc curve (RF, GB, and LR) all are step-like, is that acceptable? and thank you so much. $\endgroup$ Commented Feb 20 at 2:19

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.