Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion supervised/algorithms/xgboost.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ def time_constraint(env):


def xgboost_eval_metric(ml_task, automl_eval_metric):
# the mapping is almost the same
eval_metric_name = automl_eval_metric
if ml_task == MULTICLASS_CLASSIFICATION:
if automl_eval_metric == "logloss":
eval_metric_name = "mlogloss"
elif automl_eval_metric in ["f1", "accuracy"]:
eval_metric_name = automl_eval_metric # será manejado como custom_metric
return eval_metric_name


Expand Down
23 changes: 22 additions & 1 deletion tests/tests_fairness/test_multi_class_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pandas as pd

from supervised import AutoML
from supervised import AutoML, automl


class FairnessInMultiClassClassificationTest(unittest.TestCase):
Expand Down Expand Up @@ -53,3 +53,24 @@ def test_init(self):
self.assertTrue(len(automl._models[0].get_fairness_optimization()) > 1)
self.assertTrue(automl._models[0].get_worst_fairness() is not None)
self.assertTrue(automl._models[0].get_best_fairness() is not None)

def test_with_f1_metric(self):
X = np.random.uniform(size=(30, 2))
y = np.array(["A", "B", "C"] * 10)
S = pd.DataFrame({"sensitive": ["D", "E"] * 15})

automl = AutoML(
results_path=self.automl_dir,
model_time_limit=10,
algorithms=["Xgboost"],
eval_metric="f1", # ← el bug que se corrige
explain_level=0,
train_ensemble=False,
stack_models=False,
validation_strategy={"validation_type": "split"},
start_random_models=1,
)

automl.fit(X, y, sensitive_features=S)
self.assertGreater(len(automl._models), 0)
self.assertEqual(automl._eval_metric, "f1")