Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-vignal committed Sep 3, 2024
1 parent 0a2aba6 commit 18565d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
13 changes: 10 additions & 3 deletions shapash/webapp/smart_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
get_selected_feature,
handle_group_display_logic,
handle_page_navigation,
plot_features_importance,
select_data_from_bool_filters,
select_data_from_date_filters,
select_data_from_numeric_filters,
Expand Down Expand Up @@ -1810,8 +1809,16 @@ def update_feature_importance(
selection = get_indexes_from_datatable(data, self.list_index)

# Plot features importance
figure = plot_features_importance(
self.explainer, features, page, selection, label, group_name, bool_group, click_zoom
page_to_plot = 1 if group_name else page
zoom_active = get_figure_zoom(click_zoom)
figure = self.explainer.plot.features_importance(
max_features=features,
page=page_to_plot,
selection=selection,
label=label,
group_name=group_name,
display_groups=bool_group,
zoom=zoom_active,
)

# Determine total pages and display settings
Expand Down
40 changes: 0 additions & 40 deletions shapash/webapp/utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,46 +816,6 @@ def handle_group_display_logic(
return selected_feature, group_name, click_data, selected_click_data


def plot_features_importance(
explainer: "SmartExplainer",
features: int,
page: int,
selection: list,
label: Union[int, str],
group_name: str,
bool_group: bool,
click_zoom: bool,
) -> Figure:
"""
Plot the features importance graph.
Args:
explainer (SmartExplainer): The explainer object.
features (int): Number of features to display.
page (int): Current page number.
selection (list): List of selected features.
label (Union[int, str]): Label for the plot.
group_name (str): Name of the feature group.
bool_group (bool): Whether to display groups.
click_zoom (bool): Whether zoom is enabled.
Returns:
Figure: The features importance plot.
"""
page_to_plot = 1 if group_name else page
# Zoom is False by Default. It becomes True if we click on it
zoom_active = get_figure_zoom(click_zoom)
return explainer.plot.features_importance(
max_features=features,
page=page_to_plot,
selection=selection,
label=label,
group_name=group_name,
display_groups=bool_group,
zoom=zoom_active,
)


def determine_total_pages_and_display(
explainer: "SmartExplainer", features: int, bool_group: bool, group_name: str, page: int
) -> Tuple[int, str, int]:
Expand Down

0 comments on commit 18565d8

Please sign in to comment.