CompStats.utils

progress_bar(arg, use_tqdm: bool = True, **kwargs)[source]

Wrap arg in a tqdm.tqdm progress bar.

Returns arg unchanged when tqdm is not installed or use_tqdm is False, so callers can iterate over the result the same way regardless of whether a progress bar is actually shown.

Parameters:
  • arg – Iterable to wrap.

  • use_tqdm (bool) – Whether to show the progress bar, default=True.

  • kwargs – Extra keyword arguments passed to tqdm.tqdm.

Returns:

arg, optionally wrapped in a tqdm.tqdm iterator.

metrics_docs(hy_name='y_pred', bib: bool = True)[source]

Decorator that injects the shared Perf docstring into a CompStats.metrics wrapper (e.g. f1_score).

Parameters:
  • hy_name (str) – Name used for the predictions parameter in the generated docstring (e.g. y_pred or y_score, matching the wrapped sklearn.metrics function’s own parameter name).

  • bib (bool) – Whether the wrapped function’s measure is score-type (bigger is better) or error-type (smaller is better); used only to describe the measure’s direction in the generated docstring, matching the .BiB tag set on the wrapper’s .measure factory.

dataframe(instance, value_name: str = 'Score', var_name: str = 'Performance', alg_legend: str = 'Algorithm', perf_names: list = None)[source]

Melt a Perf or Difference instance’s bootstrap samples into a long-format pandas.DataFrame, ready for seaborn’s catplot (used by plot and plot).

Parameters:
  • instance (CompStats.interface.Perf or CompStats.interface.Difference) – Instance holding the bootstrap samples to melt.

  • value_name (str) – Column name for the statistic’s value.

  • var_name (str) – Column name identifying which measure a row belongs to, only used when instance holds more than one measure.

  • alg_legend (str) – Column name identifying which algorithm a row belongs to.

  • perf_names (list) – Display name for each measure, only used when instance holds more than one measure.

Returns:

Long-format dataframe with one row per bootstrap sample.

Return type:

pandas.DataFrame