autogluon / tabrepo

Apache License 2.0
27 stars 7 forks source link

Repo retrieves only one class for binary classification tasks #61

Open sebastianpinedaar opened 1 month ago

sebastianpinedaar commented 1 month ago

Thanks for the nice package! It fosters research in different aspects of AutoML!

However, I am curious about the expected behavior when loading the predictions for binary classification tasks (e.g. "Australian" dataset). According to the documentation, it should output a tensor with shapes: _(n_configs, n_rows, nclasses). However, the code below yields predictions of size _(n_configs, nrows).

Given that it is a binary classification problem, I expected something like _(n_configs, n_rows, nclasses), where _nclasses = 2. Is the current setup giving just the probability of one class? If so, I can easily compute the probability of the other class, however, it would be better to output directly both. Otherwise, please let me know what I am missing.

To reproduce the issue:

from tabrepo import load_repository, get_context, EvaluationRepository

context_name = "D244_F3_C1530_100"
repo: EvaluationRepository = load_repository(context_name, cache=True)

shape1 = repo.predict_val_multi(dataset="Australian",fold=0, configs=["CatBoost_r1_BAG_L1", "LightGBM_r41_BAG_L1"]).shape
shape2 = repo.predict_val_multi(dataset="autoUniv-au7-700",fold=0, configs=["CatBoost_r1_BAG_L1", "LightGBM_r41_BAG_L1"]).shape

print("Shape 1:", shape1)
print("Shape 2:", shape2)

Output:

Shape 1: (2, 621)
Shape 2: (2, 630, 3)

Regards,

Sebastian

geoalgo commented 1 month ago

Sorry for the confusion our doc is indeed to be improved there, we return a tensor with shape (n_configs, n_rows, n_classes) in case of multi-class classification and a tensor with shape (n_configs, n_rows)else for both regression and binary classification.

For binary classification, we return the probability of the first class IIRC.

Thanks for pointing this out, we will improve our doc to avoid this confusion.

Innixma commented 2 weeks ago

Yeah, @geoalgo's answer is correct. The reason we only return the positive class prediction probability is for efficiency. It allows us to halve the memory usage and runtime of the operations. It might be a good idea for us to add a flag that users can set to make it return the multiclass representation though, for ease of use purposes.

sebastianpinedaar commented 2 weeks ago

Thanks for the information! Indeed, a flag would be useful, especially if someone wants to write a general code that works for any number of classes.