Skip to content

Commit

Permalink
Fix/MetricsApp display (#169)
Browse files Browse the repository at this point in the history
- Fixed `MetricsApp` `display` method
- Added `nbformat` to dependencies
  • Loading branch information
Gooogr authored Aug 12, 2024
1 parent 4d94d8e commit cc23895
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- `Debias` mechanism for classification, ranking and auc metrics. New parameter `is_debiased` to `calc_from_confusion_df`, `calc_per_user_from_confusion_df` methods of classification metrics, `calc_from_fitted`, `calc_per_user_from_fitted` methods of auc and rankning (`MAP`) metrics, `calc_from_merged`, `calc_per_user_from_merged` methods of ranking (`NDCG`, `MRR`) metrics. ([#152](https://github.com/MobileTeleSystems/RecTools/pull/152))
- `nbformat >= 4.2.0` dependency to `[visuals]` extra ([#169](https://github.com/MobileTeleSystems/RecTools/pull/169))

### Fixed
- `display()` method in `MetricsApp` ([#169](https://github.com/MobileTeleSystems/RecTools/pull/169))

## [0.7.0] - 29.07.2024

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Pull Request Process
#. Create a virtual environment and install dependencies including all
extras and development dependencies.

#. Make sure you have ``python3`` and ``poetry==1.4.0`` installed
#. Make sure you have ``python>=3.8`` and ``poetry>=1.5.0`` installed
#. Deactivate any active virtual environments. Deactivate conda ``base``
environment if applicable
#. Run ``make install`` command which will create a virtual env and
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ See [recommender baselines extended tutorial](https://github.com/MobileTeleSyste
[Contributing guide](CONTRIBUTING.rst)

To install all requirements
- you must have `python3` and `poetry==1.4.0` installed
- you must have `python>=3.8` and `poetry>=1.5.0` installed
- make sure you have no active virtual environments (deactivate conda `base` if applicable)
- run
```
Expand Down
280 changes: 277 additions & 3 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,19 @@ pytorch-lightning = {version = ">=1.6.0, <3.0.0", optional = true}

ipywidgets = {version = ">=7.7,<8.2", optional = true}
plotly = {version="^5.22.0", optional = true}
nbformat = {version = ">=4.2.0", optional = true}


[tool.poetry.extras]
lightfm = ["rectools-lightfm"]
nmslib = ["nmslib"]
torch = ["torch", "pytorch-lightning"]
visuals = ["ipywidgets", "plotly"]
visuals = ["ipywidgets", "plotly", "nbformat"]
all = [
"rectools-lightfm",
"nmslib",
"torch", "pytorch-lightning",
"ipywidgets", "plotly",
"ipywidgets", "plotly", "nbformat",
]


Expand Down
12 changes: 4 additions & 8 deletions rectools/visuals/metrics_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,10 @@ def display(self) -> None:
options=self.meta_names,
)

# Initialize go.FigureWidget initial chart state
if not self.fig.data:
chart_data = self._create_chart_data(use_avg, fold_i)
legend_title = f"{meta_feature.value}, {DEFAULT_LEGEND_TITLE}" if use_meta.value else DEFAULT_LEGEND_TITLE
self.fig = self._create_chart_figure(
chart_data, metric_x.value, metric_y.value, Columns.Model, legend_title
)
fig_widget = go.FigureWidget(data=self.fig.data, layout=self.fig.layout)
chart_data = self._create_chart_data(use_avg, fold_i)
legend_title = f"{meta_feature.value}, {DEFAULT_LEGEND_TITLE}" if use_meta.value else DEFAULT_LEGEND_TITLE
self.fig = self._create_chart_figure(chart_data, metric_x.value, metric_y.value, Columns.Model, legend_title)
fig_widget = go.FigureWidget(data=self.fig.data, layout=self.fig.layout)

def update(event: tp.Callable[..., tp.Any]) -> None: # pragma: no cover
self._update_figure_widget(fig_widget, metric_x, metric_y, use_avg, fold_i, meta_feature, use_meta)
Expand Down
23 changes: 4 additions & 19 deletions tests/visuals/test_metrics_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.

import typing as tp
from unittest.mock import MagicMock, patch

import pandas as pd
import pytest
Expand Down Expand Up @@ -97,27 +96,13 @@ def test_happy_path(
show_legend: bool,
auto_display: bool,
scatter_kwargs: tp.Optional[tp.Dict[str, tp.Any]],
) -> None:
with patch("rectools.visuals.metrics_app.MetricsApp.display", MagicMock()):
app = MetricsApp.construct(
models_metrics=models_metrics,
models_metadata=model_metadata,
show_legend=show_legend,
auto_display=auto_display,
scatter_kwargs=scatter_kwargs,
)
_ = app.fig

@pytest.mark.parametrize("model_metadata", (None, DF_METAINFO))
def test_display(
self,
model_metadata: tp.Optional[pd.DataFrame],
) -> None:
app = MetricsApp.construct(
models_metrics=DF_METRICS,
models_metrics=models_metrics,
models_metadata=model_metadata,
show_legend=True,
auto_display=False,
show_legend=show_legend,
auto_display=auto_display,
scatter_kwargs=scatter_kwargs,
)
app.display()

Expand Down

0 comments on commit cc23895

Please sign in to comment.