Skip to content

Commit 767ca75

Browse files
Merge pull request #622 from MLecardonnel/feature/fix_report
Fix report contributions and version.
2 parents 8e35964 + f2cfa26 commit 767ca75

File tree

4 files changed

+81
-58
lines changed

4 files changed

+81
-58
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "shapash"
7-
version = "2.7.7"
7+
version = "2.7.8"
88
authors = [
99
{name = "Yann Golhen"},
1010
{name = "Sebastien Bidault"},

shapash/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (2, 7, 6)
1+
VERSION = (2, 7, 8)
22

33
__version__ = ".".join(map(str, VERSION))
Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,65 @@
11
{% if labels|length > 1 %}
2-
{% with menuId='dropdownMenuLabel', menuText='Response', values=labels, menuDivVisible='explain-all' %}
3-
{% include "dropdown.html" %}
4-
{% endwith %}
2+
{% with menuId='dropdownMenuLabel', menuText='Response', values=labels, menuDivVisible='explain-all' %}
3+
{% include "dropdown.html" %}
4+
{% endwith %}
55
{% else %}
66
{% endif %}
77
<h3 data-toc-skip>Global feature importance plot</h3>
88
{% for label in labels %}
9-
<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;">
10-
{{ label['feature_importance_plot'] }}
11-
</div>
9+
<div class="row" id="explain-all-div-{{ label['name'] }}"
10+
style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
11+
{{ label['feature_importance_plot'] }}
12+
</div>
1213
{% endfor %}
1314
<h3>Features contribution plots</h3>
1415
{% for label in labels %}
15-
<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;">
16-
{% with menuId='dropdownMenu2', menuText='Feature', values=label['features'], menuDivVisible='explain-contrib-'~label['index'] %}
17-
{% include "dropdown.html" %}
18-
{% endwith %}
19-
{% for col in label['features'] %}
20-
<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;">
21-
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
22-
{% if col['name'] != col['description'] %}
23-
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
24-
{% else %}
25-
{% endif %}
26-
{{ col['plot'] }}
27-
</div>
28-
{% endfor %}
16+
<div class="row" id="explain-all-div-{{ label['name'] }}-2"
17+
style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
18+
{% with menuId='dropdownMenu2', menuText='Feature', values=label['features'],
19+
menuDivVisible='explain-contrib-'~label['index'] %}
20+
{% include "dropdown.html" %}
21+
{% endwith %}
22+
{% for col in label['features'] %}
23+
<div class="row" id="explain-contrib-{{ label['index'] }}-div-{{ col['name'] }}"
24+
style="{% if col['feature_index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px;">
25+
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
26+
{% if col['name'] != col['description'] %}
27+
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
28+
{% else %}
29+
{% endif %}
30+
{{ col['plot'] }}
2931
</div>
32+
{% endfor %}
33+
</div>
3034
{% endfor %}
35+
{% set has_interaction = false %}
36+
{% for label in labels %}
37+
{% if label['features_interaction']|length > 0 %}
38+
{% set has_interaction = true %}
39+
{% endif %}
40+
{% endfor %}
41+
42+
{% if has_interaction %}
3143
<h3>Features Top Interaction plots</h3>
3244
{% for label in labels %}
33-
<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;">
34-
{% with menuId='dropdownMenu3', menuText='Interactions', values=label['features_interaction'], menuDivVisible='explain-contrib-interaction-'~label['index'] %}
35-
{% include "dropdown.html" %}
36-
{% endwith %}
37-
{% for col in label['features_interaction'] %}
38-
<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;">
39-
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
40-
{% if col['name'] != col['description'] %}
41-
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
42-
{% else %}
43-
{% endif %}
44-
{{ col['plot'] }}
45-
</div>
46-
{% endfor %}
45+
{% if label['features_interaction']|length > 0 %}
46+
<div class="row" id="explain-all-div-interaction-{{ label['name'] }}-2"
47+
style="{% if label['index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px; margin-top:5px;">
48+
{% with menuId='dropdownMenu3', menuText='Interactions', values=label['features_interaction'],
49+
menuDivVisible='explain-contrib-interaction-'~label['index'] %}
50+
{% include "dropdown.html" %}
51+
{% endwith %}
52+
{% for col in label['features_interaction'] %}
53+
<div class="row" id="explain-contrib-interaction-{{ label['index'] }}-div-{{ col['name'] }}"
54+
style="{% if col['feature_index'] != 0 %}display:none;{% endif %} margin-right:5px; margin-left:5px;">
55+
<h4>{{ col['name'] }} - {{ col['type'] }}</h4>
56+
{% if col['name'] != col['description'] %}
57+
<blockquote class="panel-content">{{ col['description'] }}</blockquote>
58+
{% endif %}
59+
{{ col['plot'] }}
4760
</div>
61+
{% endfor %}
62+
</div>
63+
{% endif %}
4864
{% endfor %}
65+
{% endif %}

shapash/report/project_report.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,16 @@ def display_dataset_analysis(
302302
)
303303
if target_analysis:
304304
df_target = self._create_train_test_df(
305-
test=pd.DataFrame({self.target_name: self.y_test}, index=range(len(self.y_test)))
306-
if self.y_test is not None
307-
else None,
308-
train=pd.DataFrame({self.target_name: self.y_train}, index=range(len(self.y_train)))
309-
if self.y_train is not None
310-
else None,
305+
test=(
306+
pd.DataFrame({self.target_name: self.y_test}, index=range(len(self.y_test)))
307+
if self.y_test is not None
308+
else None
309+
),
310+
train=(
311+
pd.DataFrame({self.target_name: self.y_train}, index=range(len(self.y_train)))
312+
if self.y_train is not None
313+
else None
314+
),
311315
)
312316
if df_target is not None:
313317
if target_analysis:
@@ -432,8 +436,8 @@ def display_model_explainability(self):
432436
)
433437

434438
# Interaction Plot
439+
explain_contrib_data_interaction = list()
435440
if self.display_interaction_plot:
436-
explain_contrib_data_interaction = list()
437441
list_ind, _ = self.explainer.plot._select_indices_interactions_plot(
438442
selection=None, max_points=self.max_points
439443
)
@@ -461,18 +465,18 @@ def display_model_explainability(self):
461465
}
462466
)
463467

464-
# Aggregating the data
465-
explain_data.append(
466-
{
467-
"index": index_label,
468-
"name": label_value,
469-
"feature_importance_plot": plotly.io.to_html(
470-
fig_features_importance, include_plotlyjs=False, full_html=False
471-
),
472-
"features": explain_contrib_data,
473-
"features_interaction": explain_contrib_data_interaction,
474-
}
475-
)
468+
# Aggregating the data
469+
explain_data.append(
470+
{
471+
"index": index_label,
472+
"name": label_value,
473+
"feature_importance_plot": plotly.io.to_html(
474+
fig_features_importance, include_plotlyjs=False, full_html=False
475+
),
476+
"features": explain_contrib_data,
477+
"features_interaction": explain_contrib_data_interaction,
478+
}
479+
)
476480
print_html(explainability_template.render(labels=explain_data))
477481
print_md("---")
478482

@@ -508,9 +512,11 @@ def display_model_performance(self):
508512
df = pd.concat(
509513
[
510514
pd.DataFrame({self.target_name: self.y_pred}).assign(_dataset="pred"),
511-
pd.DataFrame({self.target_name: self.y_test}).assign(_dataset="true")
512-
if self.y_test is not None
513-
else None,
515+
(
516+
pd.DataFrame({self.target_name: self.y_test}).assign(_dataset="true")
517+
if self.y_test is not None
518+
else None
519+
),
514520
]
515521
).reset_index(drop=True)
516522
self._perform_and_display_analysis_univariate(

0 commit comments

Comments
 (0)