Views
No views yet
scale_pos_weight) y publica el
ganador junto con el preprocessor.| Modelo | F1-Fraud | Precision-Fraud | Recall-Fraud | PR-AUC | ROC-AUC |
|---|---|---|---|---|---|
| Random Forest (SMOTE) | 0.3654 | 0.3455 | 0.3878 | 0.3029 | 0.8215 |
| XGBoost (scale_pos_weight) | 0.3509 | 0.3077 | 0.4082 | 0.2438 | 0.7996 |
notes/03_design_validation.md).quality (binaria: Legit / Fraud)1{
2 "n_estimators": 200,
3 "min_samples_leaf": 2,
4 "max_features": "sqrt",
5 "max_depth": null,
6 "criterion": "entropy"
7}1{
2 "subsample": 0.7,
3 "reg_lambda": 1.0,
4 "reg_alpha": 0.1,
5 "n_estimators": 500,
6 "max_depth": 6,
7 "learning_rate": 0.01,
8 "colsample_bytree": 1.0
9}1import joblib
2import pandas as pd
3from huggingface_hub import hf_hub_download
4
5repo = "gusdelact/wine-fraud-rf-vs-xgb"
6model = joblib.load(hf_hub_download(repo, "best_model.joblib"))
7preproc = joblib.load(hf_hub_download(repo, "preprocessor.joblib"))
8le = joblib.load(hf_hub_download(repo, "label_encoder.joblib"))
9
10# Construir un DataFrame con las 11 features fisicoquímicas + 'type' (red/white)
11sample = pd.DataFrame([{
12 "fixed acidity": 7.4, "volatile acidity": 0.7, "citric acid": 0.0,
13 "residual sugar": 1.9, "chlorides": 0.076, "free sulfur dioxide": 11.0,
14 "total sulfur dioxide": 34.0, "density": 0.9978, "pH": 3.51,
15 "sulphates": 0.56, "alcohol": 9.4, "type": "red"
16}])
17
18X = preproc.transform(sample)
19proba_fraud = model.predict_proba(X)[0, 1]
20threshold = 0.43861904761904763
21pred = "Fraud" if proba_fraud >= threshold else "Legit"
22print(pred, proba_fraud)theory-driven-design (ver notes/):scale_pos_weight = n_neg/n_pos para XGBoost, alternativa a SMOTE que reweighta la pérdida sin sintetizar muestras [ESL §16].StratifiedKFold(5) balancea bias y varianza del estimador de error [ISLP §5.1.4].