liveBook · Manning

Area under the curve

As explained in Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI

ROC AUC is the area under the receiver operating characteristic curve, measuring a binary classifier's ability to rank positive instances above negative instances.

ROC AUC, also called area under the curve (AUC), evaluates a binary classifier by measuring how well its predicted probabilities distinguish positive from negative instances. A score of 1 represents a perfect classifier, while 0.5 represents performance no better than random guessing. section 2.3.3

Use ROC AUC when classification performance depends on ordering and class balance makes accuracy less suitable. It is especially useful for an imbalanced binary target, where ranking predictions can be more informative than counting correct labels. section 4.2.1

Testing synthetic data

Adversarial validation combines synthetic and original records, labels their source, and trains a classifier to distinguish them. A ROC AUC of approximately 0.567 indicates that the synthetic data is almost indistinguishable from the original data. section 2.3.3

Listing 2.6 Testing a synthetic dataset using adversarial validation
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_predict
from sklearn.metrics import roc_auc_score
 
X = pd.concat([synthetic_data, data])                               #1
categorical_columns = [
    "Sex", "Housing", "Saving accounts",
    "Checking account", "Purpose"]
X_encoded = pd.get_dummies(X, columns=categorical_columns)          #2
X= X.drop("index", axis="columns") 
y = [0] * len(synthetic_data) + [1] * len(data)
 
model = RandomForestClassifier()
cv_preds = cross_val_predict(
    model,                                                          #3
    X_encoded,                                                      #3
    y,                                                              #3
    cv=5,                                                           #3
    n_jobs=-1,                                                      #3
    method="predict_proba"                                          #3
)                                                                   #3
roc_adv_score = roc_auc_score(y_true=y, y_score=cv_preds[:, 1])     #4
print(f"roc auc adv score: {roc_adv_score:0.3f}")

Inspect a scikit-learn workflow that combines datasets, encodes categorical columns, generates cross-validated predictions, and calculates ROC AUC. section 2.3.3

How Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI covers it

How deep it goes
Defines the metric, interprets benchmark scores, and demonstrates application, but does not derive the ROC curve mathematically.
Examples
Uses synthetic-versus-original German Credit Risk data and an imbalanced price-classification target as practical evaluation contexts.
What it assumes
Assumes binary classification and predicted probabilities, while introducing why accuracy may be unsuitable for imbalanced targets.
What you can do after
Evaluate binary predictions with ROC AUC and interpret scores near perfect, random, or intermediate performance.
How it connects
Connects binary classification, predicted probabilities, adversarial validation, synthetic data, accuracy, and Average Precision.

Also explained in

Compare how 12 books explain area under the curve →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI. The section links point to the parts of the book it draws on.