From 8c9c50ed555b2f14e04d90617c6299499294ba17 Mon Sep 17 00:00:00 2001 From: FAQ Bot Date: Mon, 19 Oct 2026 20:08:39 +0000 Subject: [PATCH] UPDATE: Why can a numerical feature have a ROC AUC below 0.5, and why can we inv --- ..._866f5d58d2_numerical-feature-as-auc-score.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/_questions/machine-learning-zoomcamp/module-4/029_866f5d58d2_numerical-feature-as-auc-score.md b/_questions/machine-learning-zoomcamp/module-4/029_866f5d58d2_numerical-feature-as-auc-score.md index dd30603a..1ef55e8f 100644 --- a/_questions/machine-learning-zoomcamp/module-4/029_866f5d58d2_numerical-feature-as-auc-score.md +++ b/_questions/machine-learning-zoomcamp/module-4/029_866f5d58d2_numerical-feature-as-auc-score.md @@ -1,14 +1,22 @@ --- id: 866f5d58d2 -question: 'What does ''use the numerical variable as a score'' mean for AUC?' +question: Why can a numerical feature have a ROC AUC below 0.5, and why can we invert + the feature when using AUC for feature importance? sort_order: 29 --- -You're treating each numerical feature as if it were the model's predicted score, and computing how well it discriminates the two classes: +A ROC AUC below 0.5 doesn’t mean the feature is useless—it often means the feature is predictive but in the opposite direction. + +AUC measures how well your feature values rank positive examples above negative ones. If your feature tends to give higher scores to the negative class (instead of the positive class), then the ranking is “reversed,” and the AUC can drop below 0.5. + +When you compute AUC using a single numerical feature as the `y_score`, you can flip the ranking by negating that feature: ```python from sklearn.metrics import roc_auc_score -auc = roc_auc_score(y_train, df_train['balance']) + +auc = roc_auc_score(y_train, df_train[feature]) +if auc < 0.5: + auc = roc_auc_score(y_train, -df_train[feature]) ``` -If `auc < 0.5`, invert the score by passing `-df_train['column']` (or take `1 - auc`). The numerical values don't need to be in [0, 1] — AUC only cares about ranking, not magnitudes. +Negating the feature reverses the order of the scores, turning a reversed relationship into a correctly oriented one. This is why, for feature importance based on AUC, an AUC < 0.5 can indicate meaningful predictive information—just with the opposite sign. \ No newline at end of file