MetricsApp
- class rectools.visuals.metrics_app.MetricsApp(data: DataFrame, metric_names: List[str], meta_names: List[str], show_legend: bool = True, auto_display: bool = True, scatter_kwargs: Optional[Dict[str, Any]] = None)[source]
Bases:
objectJupyter widgets app for metric visualization and comparison. Do not create instances of this class directly. Use MetricsApp.construct method instead.
- Inherited-members
- Parameters
data (DataFrame) –
metric_names (List[str]) –
meta_names (List[str]) –
show_legend (bool) –
auto_display (bool) –
scatter_kwargs (Optional[Dict[str, Any]]) –
Methods
construct(models_metrics[, models_metadata, ...])Construct interactive widget for metric-to-metric trade-off analysis.
display()Display MetricsApp widget
Attributes
Sorted list of fold identifiers from the models_metrics.
Sorted list of model names from models_metrics.
- classmethod construct(models_metrics: DataFrame, models_metadata: Optional[DataFrame] = None, show_legend: bool = True, auto_display: bool = True, scatter_kwargs: Optional[Dict[str, Any]] = None) MetricsApp[source]
Construct interactive widget for metric-to-metric trade-off analysis.
- Parameters
models_metrics (pd.DataFrame) –
- A pandas DataFrame containing metrics for visualization. Required columns:
Columns.Models - model names
Columns.Split - fold number
Any other numeric columns which represent metric values
models_metadata (tp.Optional[pd.DataFrame], optional, default None) –
An optional pandas DataFrame containing any models metadata (hyperparameters, training info, etc.). Used for alternative ways of coloring scatterplot points. Required columns:
Columns.Model - model names
Any other columns with additional information
show_legend (bool, default True) – Specifies whether to display the chart legend.
auto_display (bool, default True) – Automatically displays the widgets immediately after initialization.
scatter_kwargs (tp.Optional[tp.Dict[str, tp.Any]], optional, default None) – Additional arguments for plotly.express.scatter
- Returns
An instance of MetricsApp, providing interactive Jupyter widget for metric visualization.
- Return type
Examples
Create interactive widget
>>> metrics_df = pd.DataFrame( ... { ... Columns.Model: ["Model1", "Model2", "Model1", "Model2", "Model1", "Model2"], ... Columns.Split: [0, 0, 1, 1, 2, 2], ... "prec@10": [0.031, 0.025, 0.027, 0.21, 0.031, 0.033], ... "recall@10": [0.041, 0.045, 0.055, 0.08, 0.036, 0.021], ... "novelty@10": [2.6, 11.3, 4.3, 9.8, 3.3, 11.2], ... }) >>> # Optional metainfo about models >>> metadata_df = pd.DataFrame( ... { ... Columns.Model: ["Model1", "Model2"], ... "factors": [64, 32], ... "regularization": [0.05, 0.05], ... "alpha": [2.0, 0.5], ... }) >>> app = MetricsApp.construct( ... models_metrics=metrics_df, ... models_metadata=metadata_df, ... show_legend=True, ... auto_display=False, ... scatter_kwargs={"width": 800, "height": 600})
Get plotly chart from the current widget state
>>> fig = app.fig >>> fig = fig.update_layout(title="Metrics comparison")
- property fold_ids: Optional[List[int]]
Sorted list of fold identifiers from the models_metrics.
- property model_names: List[str]
Sorted list of model names from models_metrics.