Skip to content

[FAQ Bot] UPDATE: Why can a numerical feature have a ROC AUC below 0.5, and why can we inv - #479

Open
github-actions[bot] wants to merge 1 commit into
mainfrom
faq-bot/issue-478
Open

github-actions[bot] wants to merge 1 commit into
mainfrom
faq-bot/issue-478

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

📝 FAQ UPDATE

Course: machine-learning-zoomcamp
Section: module-4 (The proposal is directly about ROC AUC behavior for numerical features in classification, which fits Module 4’s coverage of ROC curves and ROC AUC.)
Related Issue: #478

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?

Decision Rationale

Existing FAQs explain how to use AUC as a score and mention inverting when auc < 0.5, but they don’t explicitly explain why AUC can be below 0.5 (opposite-direction relationship) and how/why negation changes ranking for feature importance.

Placement Details

  • Section ID: module-4
  • Sort Order: 30
  • Document ID: 866f5d58d2

⚠️ Warnings

  • This will effectively merge into the existing Module 4 AUC/feature-score FAQ (document_id 866f5d58d2), adding the missing ‘why < 0.5’ explanation.

🤖 Generated by FAQ Bot

Closes #478

@saeidsoheily

Copy link
Copy Markdown

A numerical feature can have ROC AUC below 0.5 when its relationship with the target is reversed: lower feature values tend to correspond to the positive class (y=1), rather than higher values.

This does not necessarily mean the feature is useless. It may be a strong predictor in the opposite direction.

When evaluating a numerical feature directly using roc_auc_score(), we treat its values as prediction scores.

ROC AUC measures how well those scores rank positive examples above negative examples.

  • AUC = 1.0: Positive examples consistently have higher values.
  • AUC = 0.5: No ranking discrimination.
  • AUC below 0.5: Negative examples tend to have higher values.
  • AUC = 0.0: Perfect ranking in the opposite direction.

In Module 4, we can use ROC AUC to evaluate the predictive strength of individual numerical features.

from sklearn.metrics import roc_auc_score

for feature in numerical:
    auc = roc_auc_score(df_train.y, df_train[feature])

    if auc < 0.5:
        auc = roc_auc_score(df_train.y, -df_train[feature])

    print(f"{feature:30s} AUC = {auc:.3f}")

Alternatively, since negation reverses AUC:

for feature in numerical:
    auc = roc_auc_score(df_train.y, df_train[feature])
    auc = max(auc, 1 - auc)

    print(f"{feature:30s} AUC = {auc:.3f}")

This produces a direction-independent AUC between 0.5 and 1.0.

In simple words; Negating a feature does not add information or make the underlying feature more predictive. It simply reverses which direction counts as a higher score.

Also, single-feature AUC is only one measure of feature importance. It does not capture interactions, redundancy between features, or how much a feature improves a multivariate model.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FAQ]Why can a numerical feature have ROC AUC below 0.5, and why can we invert it?

1 participant