gusdelact/credit-card-fraud-curated
Viewer • Updated • 2.89M • 113
Clasificador binario de fraude en transacciones con tarjeta de crédito.
Entrenado sobre gusdelact/credit-card-fraud-curated
(curación de alenc123/credit-card-fraud).
XGBClassifieris_fraudalenc123/credit-card-fraud (1.3M filas).{
"subsample": 0.8,
"n_estimators": 400,
"max_depth": 6,
"learning_rate": 0.05,
"colsample_bytree": 0.7
}
scale_pos_weight = 171.66 (≈ n_neg / n_pos), en lugar de SMOTE.tree_method = "hist" para eficiencia en CPU.| Métrica | Umbral 0.5 | Umbral óptimo (0.964) |
|---|---|---|
| Accuracy | 0.9940 | 0.9983 |
| Precision (fraude) | 0.4901 | 0.9184 |
| Recall (fraude) | 0.9251 | 0.7781 |
| F1 (fraude) | 0.6407 | 0.8424 |
| Métrica global | |
|---|---|
| ROC-AUC | 0.9970 |
| PR-AUC | 0.8946 |
| F1 CV (búsqueda hp) | 0.7081 |
El umbral óptimo se calibra por F1 sobre la curva precision-recall del test set. La elección final del umbral en producción depende del costo relativo entre falsos negativos (fraude no detectado) y falsos positivos (transacción legítima rechazada).
import joblib
import json
import pandas as pd
from huggingface_hub import hf_hub_download
REPO = "gusdelact/credit-card-fraud-xgboost"
model = joblib.load(hf_hub_download(REPO, "model.joblib"))
preprocessor = joblib.load(hf_hub_download(REPO, "preprocessor.joblib"))
schema = json.load(open(hf_hub_download(REPO, "feature_schema.json")))
# Preparar features crudas (debe incluir trans_date_trans_time, dob, lat, long,
# merch_lat, merch_long, amt, category, gender, state, city_pop)
# y derivar hour/day_of_week/month/age/distance_km como en el pipeline original.
# Ver app_inference/app_inference.py para un ejemplo completo.
El diseño completo está en notes/0[1-3]_design_*.md del repositorio. En síntesis:
learning_rate pequeño + muchos
árboles equivale a una regularización L1 monótona en el espacio de árboles
(ESL §16.2.2). Con esta estructura el sobreajuste tiende a aparecer
lentamente.L_kk' = n_neg / n_pos desplaza la frontera de Bayes hacia mayor
recall, equivalente a scale_pos_weight en XGBoost.cc_num: el split actual no agrupa por tarjeta. Una
versión futura debería usar GroupKFold(groups=cc_num).state es un campo de
estados americanos.category es OneHot fijo: categorías no vistas en train se ignoran
(handle_unknown="ignore").@model{credit-card-fraud-xgboost,
author = {gusdelact},
title = {credit-card-fraud-xgboost},
year = {2026},
publisher = {Hugging Face Hub}
}