Skip to content

Commit

Permalink
Merge pull request #622 from MLecardonnel/feature/fix_report
Browse files Browse the repository at this point in the history
Fix report contributions and version.
  • Loading branch information
guillaume-vignal authored Feb 13, 2025
2 parents 8e35964 + f2cfa26 commit 767ca75
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 58 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "shapash"
version = "2.7.7"
version = "2.7.8"
authors = [
{name = "Yann Golhen"},
{name = "Sebastien Bidault"},
Expand Down
2 changes: 1 addition & 1 deletion shapash/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (2, 7, 6)
VERSION = (2, 7, 8)

__version__ = ".".join(map(str, VERSION))
85 changes: 51 additions & 34 deletions shapash/report/html/explainability.html
Original file line number Diff line number Diff line change
@@ -1,48 +1,65 @@
{% if labels|length > 1 %}
{% with menuId='dropdownMenuLabel', menuText='Response', values=labels, menuDivVisible='explain-all' %}
{% include "dropdown.html" %}
{% endwith %}
{% with menuId='dropdownMenuLabel', menuText='Response', values=labels, menuDivVisible='explain-all' %}
{% include "dropdown.html" %}
{% endwith %}
{% else %}
{% endif %}
<h3 data-toc-skip>Global feature importance plot</h3>
{% for label in labels %}
<div class="row" id="explain-all-div-{{ label['name'] }}" style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
{{ label['feature_importance_plot'] }}
</div>
<div class="row" id="explain-all-div-{{ label['name'] }}"
style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
{{ label['feature_importance_plot'] }}
</div>
{% endfor %}
<h3>Features contribution plots</h3>
{% for label in labels %}
<div class="row" id="explain-all-div-{{ label['name'] }}-2" style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
{% with menuId='dropdownMenu2', menuText='Feature', values=label['features'], menuDivVisible='explain-contrib-'~label['index'] %}
{% include "dropdown.html" %}
{% endwith %}
{% for col in label['features'] %}
<div class="row" id="explain-contrib-{{ label['index'] }}-div-{{ col['name'] }}" style="{% if col['feature_index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px;">
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
{% if col['name'] != col['description'] %}
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
{% else %}
{% endif %}
{{ col['plot'] }}
</div>
{% endfor %}
<div class="row" id="explain-all-div-{{ label['name'] }}-2"
style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
{% with menuId='dropdownMenu2', menuText='Feature', values=label['features'],
menuDivVisible='explain-contrib-'~label['index'] %}
{% include "dropdown.html" %}
{% endwith %}
{% for col in label['features'] %}
<div class="row" id="explain-contrib-{{ label['index'] }}-div-{{ col['name'] }}"
style="{% if col['feature_index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px;">
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
{% if col['name'] != col['description'] %}
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
{% else %}
{% endif %}
{{ col['plot'] }}
</div>
{% endfor %}
</div>
{% endfor %}
{% set has_interaction = false %}
{% for label in labels %}
{% if label['features_interaction']|length > 0 %}
{% set has_interaction = true %}
{% endif %}
{% endfor %}

{% if has_interaction %}
<h3>Features Top Interaction plots</h3>
{% for label in labels %}
<div class="row" id="explain-all-div-interaction-{{ label['name'] }}-2" style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
{% with menuId='dropdownMenu3', menuText='Interactions', values=label['features_interaction'], menuDivVisible='explain-contrib-interaction-'~label['index'] %}
{% include "dropdown.html" %}
{% endwith %}
{% for col in label['features_interaction'] %}
<div class="row" id="explain-contrib-interaction-{{ label['index'] }}-div-{{ col['name'] }}" style="{% if col['feature_index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px;">
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
{% if col['name'] != col['description'] %}
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
{% else %}
{% endif %}
{{ col['plot'] }}
</div>
{% endfor %}
{% if label['features_interaction']|length > 0 %}
<div class="row" id="explain-all-div-interaction-{{ label['name'] }}-2"
style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
{% with menuId='dropdownMenu3', menuText='Interactions', values=label['features_interaction'],
menuDivVisible='explain-contrib-interaction-'~label['index'] %}
{% include "dropdown.html" %}
{% endwith %}
{% for col in label['features_interaction'] %}
<div class="row" id="explain-contrib-interaction-{{ label['index'] }}-div-{{ col['name'] }}"
style="{% if col['feature_index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px;">
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
{% if col['name'] != col['description'] %}
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
{% endif %}
{{ col['plot'] }}
</div>
{% endfor %}
</div>
{% endif %}
{% endfor %}
{% endif %}
50 changes: 28 additions & 22 deletions shapash/report/project_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,16 @@ def display_dataset_analysis(
)
if target_analysis:
df_target = self._create_train_test_df(
test=pd.DataFrame({self.target_name: self.y_test}, index=range(len(self.y_test)))
if self.y_test is not None
else None,
train=pd.DataFrame({self.target_name: self.y_train}, index=range(len(self.y_train)))
if self.y_train is not None
else None,
test=(
pd.DataFrame({self.target_name: self.y_test}, index=range(len(self.y_test)))
if self.y_test is not None
else None
),
train=(
pd.DataFrame({self.target_name: self.y_train}, index=range(len(self.y_train)))
if self.y_train is not None
else None
),
)
if df_target is not None:
if target_analysis:
Expand Down Expand Up @@ -432,8 +436,8 @@ def display_model_explainability(self):
)

# Interaction Plot
explain_contrib_data_interaction = list()
if self.display_interaction_plot:
explain_contrib_data_interaction = list()
list_ind, _ = self.explainer.plot._select_indices_interactions_plot(
selection=None, max_points=self.max_points
)
Expand Down Expand Up @@ -461,18 +465,18 @@ def display_model_explainability(self):
}
)

# Aggregating the data
explain_data.append(
{
"index": index_label,
"name": label_value,
"feature_importance_plot": plotly.io.to_html(
fig_features_importance, include_plotlyjs=False, full_html=False
),
"features": explain_contrib_data,
"features_interaction": explain_contrib_data_interaction,
}
)
# Aggregating the data
explain_data.append(
{
"index": index_label,
"name": label_value,
"feature_importance_plot": plotly.io.to_html(
fig_features_importance, include_plotlyjs=False, full_html=False
),
"features": explain_contrib_data,
"features_interaction": explain_contrib_data_interaction,
}
)
print_html(explainability_template.render(labels=explain_data))
print_md("---")

Expand Down Expand Up @@ -508,9 +512,11 @@ def display_model_performance(self):
df = pd.concat(
[
pd.DataFrame({self.target_name: self.y_pred}).assign(_dataset="pred"),
pd.DataFrame({self.target_name: self.y_test}).assign(_dataset="true")
if self.y_test is not None
else None,
(
pd.DataFrame({self.target_name: self.y_test}).assign(_dataset="true")
if self.y_test is not None
else None
),
]
).reset_index(drop=True)
self._perform_and_display_analysis_univariate(
Expand Down

0 comments on commit 767ca75

Please sign in to comment.