tabensemb.utils.utils#

All utilities used in the project.

Functions

add_postfix(path)

If the input path exists, add a postfix f"-I{n}" to it, where n increases if path ends with f"-I{n}".

auto_metric_sklearn(y_true, y_pred, metric, task)

Calculate metrics using sklearn APIs.

check_stream()

A utility of HiddenPrints().

convert_proba_to_target(y_pred, task)

Convert probabilities of classes to the class of each sample.

convert_target_to_indicator(y_pred, n_classes)

Convert the class of each sample to class indicator.

debugger_is_active()

Return True if the debugger is currently active

get_figsize(n, max_col, width_per_item, ...)

Calculate the figsize argument of matplotlib for a figure with subplots.

gini(x[, w])

Calculate the gini index of a feature.

is_notebook()

Check whether the current environment is a notebook.

metric_sklearn(y_true, y_pred, metric)

Calculate metrics using sklearn APIs.

pretty(value[, htchar, lfchar, indent])

Represent a dictionary, a list, or a tuple by a string.

reload_module(name)

Re-import the module.

safe_mkdir(path)

Make a previously not existing directory safely resolving conflicts.

seed_worker(worker_id)

For the argument worker_init_fn of torch.utils.data.DataLoader.

set_random_seed([seed])

Set random seeds of pytorch (including cuda and dataloaders), numpy, and random.

set_torch([seed])

Set the random seed of pytorch, CUDA, and torch.utils.data.DataLoader.

str_to_dataframe(s[, sep, names, check_nan_on])

Convert a .csv type of string to a dataframe.

update_defaults_by_kwargs([defaults, kwargs])

Classes

HiddenPltShow()

A context manager that temporarily hide all matplotlib.pyplot.show().

HiddenPrints([disable_logging, disable_std])

A context manager that can temporarily hide all sys.stdout outputs and logging outputs.

Logger(path, stream)

Capture all outputs to a log file while still printing it.

Logging()

Capture all outputs to a log file while still printing it.

PickleAbleGenerator(generator[, ...])

Turn a generator (not pickle-able) into a pickle-able object by extracting all items in the generator to a list.

PlainText([disable])

A context manager that can temporarily redirect all sys.stderr outputs to sys.stdout.

TqdmController()

A controller of tqdm progress bars, including tqdm.tqdm, tqdm.notebook.tqdm, and tqdm.auto.tqdm.

global_setting(setting)

A context manager that temporarily changes the global setting tabensemb.setting.

torch_with_grad()

A context manager that enabled gradient calculation.