Skip to content

Commit e905504

Browse files
committed
various fix
1 parent 672c28a commit e905504

File tree

18 files changed

+294
-270
lines changed

18 files changed

+294
-270
lines changed

eurybia/assets/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""asset package."""

eurybia/core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""core package."""

eurybia/core/smartdrift.py

Lines changed: 59 additions & 55 deletions
Large diffs are not rendered by default.

eurybia/core/smartplotter.py

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
"""
2-
Smart plotter module
3-
"""
1+
"""Smart plotter module"""
42

53
import copy
64

7-
# ----- Eurybia packages
8-
from typing import Optional
9-
105
import matplotlib.pyplot as plt
116
import numpy as np
127
import pandas as pd
@@ -22,22 +17,22 @@
2217

2318

2419
class SmartPlotter:
25-
"""
26-
The smartplotter class includes all the methods used to display graphics
20+
"""The smartplotter class includes all the methods used to display graphics
2721
2822
Each SmartPlotter method is easy to use from a Smart Drift object,
2923
just use the following syntax
3024
31-
Attributes
25+
Attributes:
3226
----------
3327
smartdrift: object
3428
SmartDrift object
3529
_palette_name : str (default: 'eurybia')
3630
Name of the palette used for the colors of the report (refer to style folder).
3731
_style_dict: dict
3832
Dict contains dicts of the colors used in the different plots
39-
Example
40-
--------
33+
34+
Example:
35+
-------
4136
>>> SD = Smartdrift()
4237
>>> SD.compile()
4338
>>> SD.plot.my_plot_method(param=value)
@@ -52,12 +47,11 @@ def __init__(self, smartdrift):
5247
def generate_fig_univariate(
5348
self,
5449
col: str,
55-
hue: Optional[str] = None,
56-
df_all: Optional[pd.DataFrame] = None,
57-
dict_color_palette: Optional[dict] = None,
50+
hue: str | None = None,
51+
df_all: pd.DataFrame | None = None,
52+
dict_color_palette: dict | None = None,
5853
) -> plt.Figure:
59-
"""
60-
Returns a plotly figure containing the distribution of any kind of feature
54+
"""Returns a plotly figure containing the distribution of any kind of feature
6155
(continuous, categorical).
6256
6357
If the feature is categorical and contains too many categories, the smallest
@@ -81,6 +75,7 @@ def generate_fig_univariate(
8175
Returns
8276
-------
8377
plotly.graph_objs._figure.Figure
78+
8479
"""
8580
if hue is None:
8681
hue = self.smartdrift._datadrift_target
@@ -105,17 +100,16 @@ def generate_fig_univariate_continuous(
105100
col: str,
106101
hue: str,
107102
dict_color_palette: dict,
108-
template: Optional[str] = None,
109-
title: Optional[str] = None,
110-
xaxis_title: Optional[dict] = None,
111-
yaxis_title: Optional[dict] = None,
112-
xaxis: Optional[str] = None,
113-
height: Optional[str] = None,
114-
width: Optional[str] = None,
115-
hovermode: Optional[str] = None,
103+
template: str | None = None,
104+
title: str | None = None,
105+
xaxis_title: dict | None = None,
106+
yaxis_title: dict | None = None,
107+
xaxis: str | None = None,
108+
height: str | None = None,
109+
width: str | None = None,
110+
hovermode: str | None = None,
116111
) -> plotly.graph_objs._figure.Figure:
117-
"""
118-
Returns a plotly figure containing the distribution of a continuous feature.
112+
"""Returns a plotly figure containing the distribution of a continuous feature.
119113
120114
Parameters
121115
----------
@@ -141,9 +135,11 @@ def generate_fig_univariate_continuous(
141135
Width of the plot
142136
hovermode: str,n , optional
143137
Type of labels displaying on mouse hovering
138+
144139
Returns
145140
-------
146141
plotly.graph_objs._figure.Figure
142+
147143
"""
148144
df_all[col] = df_all[col].fillna(0)
149145
datasets = [df_all[df_all[hue] == val][col].values.tolist() for val in df_all[hue].unique()]
@@ -201,18 +197,17 @@ def generate_fig_univariate_categorical(
201197
hue: str,
202198
dict_color_palette: dict,
203199
nb_cat_max: int = 15,
204-
template: Optional[str] = None,
205-
title: Optional[str] = None,
206-
xaxis_title: Optional[dict] = None,
207-
yaxis_title: Optional[dict] = None,
208-
xaxis: Optional[str] = None,
209-
height: Optional[str] = None,
210-
width: Optional[str] = None,
211-
hovermode: Optional[str] = None,
212-
legend: Optional[str] = None,
200+
template: str | None = None,
201+
title: str | None = None,
202+
xaxis_title: dict | None = None,
203+
yaxis_title: dict | None = None,
204+
xaxis: str | None = None,
205+
height: str | None = None,
206+
width: str | None = None,
207+
hovermode: str | None = None,
208+
legend: str | None = None,
213209
) -> plotly.graph_objs._figure.Figure:
214-
"""
215-
Returns a plotly figure containing the distribution of a categorical feature.
210+
"""Returns a plotly figure containing the distribution of a categorical feature.
216211
217212
If the feature is categorical and contains too many categories, the smallest
218213
categories are grouped into a new 'Other' category so that the graph remains
@@ -248,9 +243,11 @@ def generate_fig_univariate_categorical(
248243
Type of labels displaying on mouse hovering
249244
legend: str, optional
250245
Axis legends
246+
251247
Returns
252248
-------
253249
plotly.graph_objs._figure.Figure
250+
254251
"""
255252
df_cat = df_all.groupby([col, hue]).agg({col: "count"}).rename(columns={col: "count"}).reset_index()
256253
df_cat["Percent"] = df_cat["count"] * 100 / df_cat.groupby(hue)["count"].transform("sum")
@@ -340,8 +337,7 @@ def generate_fig_univariate_categorical(
340337
return fig
341338

342339
def _merge_small_categories(self, df_cat: pd.DataFrame, col: str, hue: str, nb_cat_max: int) -> pd.DataFrame:
343-
"""
344-
Merges categories of column 'col' of df_cat into 'Other' category so that
340+
"""Merges categories of column 'col' of df_cat into 'Other' category so that
345341
the number of categories is less than nb_cat_max.
346342
"""
347343
df_cat_sum_hue = df_cat.groupby([col]).agg({"count": "sum"}).reset_index()
@@ -355,8 +351,7 @@ def _merge_small_categories(self, df_cat: pd.DataFrame, col: str, hue: str, nb_c
355351
def scatter_feature_importance(
356352
self, feature_importance: pd.DataFrame = None, datadrift_stat_test: pd.DataFrame = None
357353
) -> plotly.graph_objs._figure.Figure:
358-
"""
359-
Displays scatter of feature importance between drift
354+
"""Displays scatter of feature importance between drift
360355
model and production one extracted from a datasets created
361356
during the compile step.
362357
@@ -366,9 +361,11 @@ def scatter_feature_importance(
366361
DataFrame containing feature importance for each features from production and drift model.
367362
datadrift_stat_test: pd.DataFrame, optional
368363
DataFrame containing the result of datadrift univariate tests
364+
369365
Returns
370366
-------
371367
plotly.express.scatter
368+
372369
"""
373370
dict_t = copy.deepcopy(self._style_dict["dict_title"])
374371
dict_xaxis = copy.deepcopy(self._style_dict["dict_xaxis_title"])
@@ -388,14 +385,15 @@ def scatter_feature_importance(
388385
# symbols
389386
stat_test_list = list(data["testname"].unique())
390387
symbol_list = [0, 13]
391-
symbol_dict = dict(zip(stat_test_list, symbol_list))
388+
symbol_dict = dict(zip(stat_test_list, symbol_list, strict=True))
392389

393390
hv_text = [
394-
f"<b>Feature: {feat}</b><br />Deployed Model Importance: {depimp*100:.1f}%<br />"
391+
f"<b>Feature: {feat}</b><br />Deployed Model Importance: {depimp * 100:.1f}%<br />"
395392
+ f"Datadrift test: {t} - pvalue: {pv:.5f}<br />"
396-
+ f"Datadrift model Importance: {ddrimp*100:.1f}"
393+
+ f"Datadrift model Importance: {ddrimp * 100:.1f}"
397394
for feat, depimp, t, pv, ddrimp in zip(
398-
*map(data.get, ["features", "deployed_model", "testname", "pvalue", "datadrift_classifier"])
395+
*map(data.get, ["features", "deployed_model", "testname", "pvalue", "datadrift_classifier"]),
396+
strict=True,
399397
)
400398
]
401399

@@ -439,18 +437,18 @@ def scatter_feature_importance(
439437
def generate_historical_datadrift_metric(
440438
self,
441439
datadrift_historical: pd.DataFrame = None,
442-
template: Optional[str] = None,
443-
title: Optional[str] = None,
444-
xaxis_title: Optional[str] = None,
445-
yaxis_title: Optional[str] = None,
446-
xaxis: Optional[str] = None,
447-
height: Optional[str] = None,
448-
width: Optional[str] = None,
449-
hovermode: Optional[str] = None,
440+
template: str | None = None,
441+
title: str | None = None,
442+
xaxis_title: str | None = None,
443+
yaxis_title: str | None = None,
444+
xaxis: str | None = None,
445+
height: str | None = None,
446+
width: str | None = None,
447+
hovermode: str | None = None,
450448
) -> plotly.graph_objs._figure.Figure:
451-
"""
452-
Displays line plot of the evolution of the datadrift metrics :
449+
"""Displays line plot of the evolution of the datadrift metrics :
453450
AUC of Datadrift classifier and if deployed_model fill, Jensen Shannon divergence of distribution of prediction
451+
454452
Parameters
455453
----------
456454
datadrift_historical : pd.DataFrame
@@ -471,9 +469,11 @@ def generate_historical_datadrift_metric(
471469
Width of the plot
472470
hovermode: str, optional
473471
Type of labels displaying on mouse hovering
472+
474473
Returns
475474
-------
476475
plotly.express.line
476+
477477
"""
478478
if datadrift_historical is None:
479479
datadrift_historical = self.smartdrift.historical_auc
@@ -556,17 +556,16 @@ def generate_modeldrift_data(
556556
data_modeldrift: pd.DataFrame = None,
557557
metric: str = "performance",
558558
reference_columns: list = list(),
559-
template: Optional[str] = None,
560-
title: Optional[str] = None,
561-
xaxis_title: Optional[str] = None,
562-
yaxis_title: Optional[dict] = None,
563-
xaxis: Optional[str] = None,
564-
height: Optional[str] = None,
565-
width: Optional[str] = None,
566-
hovermode: Optional[str] = None,
559+
template: str | None = None,
560+
title: str | None = None,
561+
xaxis_title: str | None = None,
562+
yaxis_title: dict | None = None,
563+
xaxis: str | None = None,
564+
height: str | None = None,
565+
width: str | None = None,
566+
hovermode: str | None = None,
567567
) -> plotly.graph_objs._figure.Figure:
568-
"""
569-
Displays line plot of the evolution of the Lift computed for deployed model with several criterias.
568+
"""Displays line plot of the evolution of the Lift computed for deployed model with several criterias.
570569
571570
Parameters
572571
----------
@@ -590,9 +589,11 @@ def generate_modeldrift_data(
590589
Width of the plot
591590
hovermode: str, optional
592591
Type of labels displaying on mouse hovering
592+
593593
Returns
594594
-------
595595
plotly.express.line
596+
596597
"""
597598
if data_modeldrift is None:
598599
data_modeldrift = self.smartdrift.data_modeldrift
@@ -649,12 +650,13 @@ def generate_modeldrift_data(
649650
return fig
650651

651652
def define_style_attributes(self, colors_dict):
652-
"""
653-
define_style_attributes allows Eurybia user to change the color of plot
653+
"""define_style_attributes allows Eurybia user to change the color of plot
654+
654655
Parameters
655656
----------
656657
colors_dict: dict
657658
Dict of the colors used in the different plots
659+
658660
"""
659661
self._style_dict = define_style(colors_dict)
660662

@@ -666,12 +668,12 @@ def generate_indicator(
666668
fig_value: float,
667669
min_gauge: float = 0.5,
668670
max_gauge: float = 1,
669-
height: Optional[float] = 300,
670-
width: Optional[float] = 500,
671-
title: Optional[str] = "Metric",
671+
height: float | None = 300,
672+
width: float | None = 500,
673+
title: str | None = "Metric",
672674
) -> plotly.graph_objs._figure.Figure:
673-
"""
674-
Displays an indicator in a colorbar
675+
"""Displays an indicator in a colorbar
676+
675677
Parameters
676678
----------
677679
fig_value: float
@@ -686,6 +688,7 @@ def generate_indicator(
686688
Width of the plot
687689
title: str, optional
688690
Plot title
691+
689692
"""
690693
color = sns.blend_palette(["green", "yellow", "orange", "red"], 100)
691694
color = color.as_hex()

eurybia/data/data_loader.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""
2-
Data loader module
3-
"""
1+
"""Data loader module"""
42

53
import json
64
import os
@@ -10,8 +8,7 @@
108

119

1210
def data_loading(dataset):
13-
"""
14-
data_loading allows Eurybia user to try the library with small but clear datasets.
11+
"""data_loading allows Eurybia user to try the library with small but clear datasets.
1512
Titanic, house_prices or us_car_accident data.
1613
1714
Example
@@ -33,6 +30,7 @@ def data_loading(dataset):
3330
Dataset required
3431
dict : (Dictionnary, Optional)
3532
If exist, columns labels dictionnary associated to the dataset.
33+
3634
"""
3735
current_path = os.path.dirname(os.path.abspath(__file__))
3836
if dataset == "house_prices":

eurybia/report/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""report package."""

0 commit comments

Comments
 (0)