ablator.analysis.plot package#

Submodules#

ablator.analysis.plot.cat_plot module#

class ablator.analysis.plot.cat_plot.Categorical(*args, **kwargs)[source]#

Bases: Plot

DATA_TYPE = 'categorical'#
class ablator.analysis.plot.cat_plot.ViolinPlot(*args, **kwargs)[source]#

Bases: Categorical

ablator.analysis.plot.main module#

class ablator.analysis.plot.main.PlotAnalysis(results: DataFrame | Results, categorical_attributes: list[str] | None = None, numerical_attributes: list[str] | None = None, optim_metrics: dict[str, ablator.config.mp.Optim] | None = None, save_dir: str | None = None, cache=False)[source]#

Bases: Analysis

Class for plotting experiment results. You can use this class and Results class to visualize the relationship between any hyperparameter that you run ablation study on with the result metrics. This valuable insight offers an intuitive understanding of how these parameters may influence your model’s performance.

Plots supported are linear plots for numerical data and violin plots for categorical data.

Examples

  • Data frame to be used:

>>> df2 = pd.DataFrame({'val_accuracy': np.random.uniform(0.8,0.9,10),
...       'train_config.optimizer_config.arguments.lr': np.random.uniform(0.001, 0.1,10),
...       "index": range(10),
...       "path": range(10)})
  • Creating dictionaries that map the configuration parameters [categorical + numerical] to custom labels for plots:

>>> numerical_name_remap = {
...             "train_config.optimizer_config.arguments.lr": "Learning Rate",
...         }
...     categorical_name_remap = {}
...     attribute_name_remap = {**categorical_name_remap, **numerical_name_remap}
  • Initalize the PlotAnalysis and plot the figures:

>>> analysis = PlotAnalysis(
...     df,
...     save_dir="./plots",
...     cache=True,
...     optim_metrics={"val_accuracy": Optim.max},
...     numerical_attributes=list(numerical_name_remap.keys()),
...     categorical_attributes=list(categorical_name_remap.keys()),
... )
>>> analysis.make_figures(
...    metric_name_remap={
...        "val_accuracy": "Validation Accuracy",
...    },
...    attribute_name_remap= attribute_name_remap
... )

The directory "plots" contains all the plots of the HPO experiments

make_figures(metric_name_remap: dict[str, str] | None = None, attribute_name_remap: dict[str, str] | None = None, **plt_kwargs)[source]#
make_linearplot(attribute_names: list[str], metrics: list[str], save_dir: Path | str, **plt_kwargs)[source]#
make_violinplot(attribute_names: list[str], metrics: list[str], save_dir: Path | str, **plt_kwargs)[source]#

ablator.analysis.plot.num_plot module#

class ablator.analysis.plot.num_plot.LinearPlot(metric: Series, attributes: Series, metric_obj_fn: Optim, y_axis: str | None = None, x_axis: str | None = None, x_ticks: ndarray | None = None, ax: Axes | None = None)[source]#

Bases: Numerical

class ablator.analysis.plot.num_plot.Numerical(metric: Series, attributes: Series, metric_obj_fn: Optim, y_axis: str | None = None, x_axis: str | None = None, x_ticks: ndarray | None = None, ax: Axes | None = None)[source]#

Bases: Plot

DATA_TYPE = 'numerical'#

ablator.analysis.plot.utils module#

ablator.analysis.plot.utils.parse_name_remap(defaults: list[str] | None = None, name_map: dict[str, str] | None = None) dict[str, str][source]#

Returns a dictionary mapping input attribute names to output attribute names, with optional remapping based on name_map.

Parameters:
defaultslist of str or None, optional

The default attribute names to use as keys in the output dictionary. If None, the output dictionary will be based on name_map only.

name_mapdict of str to str or None, optional

A dictionary mapping input attribute names to output attribute names. If None, the output dictionary will be based on defaults only.

Returns:
dict of str to str

A dictionary mapping input attribute names to output attribute names.

Raises:
NotImplementedError

If defaults and name_map are both None.

Examples

>>> defaults = ["attr1", "attr2", "attr3"]
>>> name_map = {"attr2": "new_attr2", "attr4": "attr4_renamed"}
>>> name_remap = parse_name_remap(defaults, name_map)
>>> assert name_remap == {"attr1": "attr1", "attr2": "new_attr2", "attr3": "attr3"}
>>> name_remap = parse_name_remap(defaults)
>>> assert name_remap == {"attr1": "attr1", "attr2": "attr2", "attr3": "attr3"}
>>> name_remap = parse_name_remap(name_map=name_map)
>>> assert name_remap == {"attr2": "new_attr2", "attr4": "attr4_renamed"}

Module contents#

class ablator.analysis.plot.Plot(metric: Series, attributes: Series, metric_obj_fn: Optim, y_axis: str | None = None, x_axis: str | None = None, x_ticks: ndarray | None = None, ax: Axes | None = None)[source]#

Bases: ABC

make(**kwargs)[source]#