Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #571: Compatibility with >= Numpy 2.0.0 (update of ptp method) #572

Merged
merged 3 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/dalex/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### development

* replaced instances of x.ptp() (with np.ptp(x)) and np.Inf (with np.inf) to make dx compatible with Numpy>=2.0.0
* added a way to pass `sample_weight` to loss functions in `model_parts()` (variable importance) using `weights` from `dx.Explainer` ([#563](https://github.com/ModelOriented/DALEX/issues/563))
* fixed the visualization of `shap_wrapper` for `shap==0.45.0`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def plot(
dl = _result_df.loc[
_result_df.aspect_name != "_baseline_", "dropout_loss"
].to_numpy()
min_max_margin = dl.ptp() * 0.15
min_max_margin = np.ptp(dl) * 0.15
min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin]

# take out full model
Expand Down
4 changes: 2 additions & 2 deletions python/dalex/dalex/aspect/_model_triplot/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def plot(
fig.data[0]["y"] = y_vals

## triplot
min_x_imp, max_x_imp = np.Inf, -np.Inf
min_x_imp, max_x_imp = np.inf, -np.inf
for data in hierarchical_importance_dendrogram_plot["data"][::-1]:
data["xaxis"] = "x2"
data["hoverinfo"] = "text"
Expand All @@ -241,7 +241,7 @@ def plot(
max_x_imp = np.max([max_x_imp, np.max(data["x"])])
min_max_margin_imp = (max_x_imp - min_x_imp) * 0.15

min_x_clust, max_x_clust = np.Inf, -np.Inf
min_x_clust, max_x_clust = np.inf, -np.inf
for data in hierarchical_clustering_dendrogram_plot["data"]:
data["xaxis"] = "x3"
data["hoverinfo"] = "text"
Expand Down
4 changes: 2 additions & 2 deletions python/dalex/dalex/aspect/_model_triplot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ def plot_single_aspects_importance(
}
)

temp_min_max = [np.Inf, -np.Inf]
min_max_margin = _result.dropout_loss.values.ptp() * 0.15
temp_min_max = [np.inf, -np.inf]
min_max_margin = np.ptp(_result.dropout_loss.values) * 0.15
temp_min_max[0] = np.min(
[temp_min_max[0], baseline - min_max_margin]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def plot(
vcolors = _theme.get_aspect_importance_colors()

if min_max is None:
temp_min_max = [np.Inf, -np.Inf]
temp_min_max = [np.inf, -np.inf]
else:
temp_min_max = min_max

Expand Down Expand Up @@ -404,7 +404,7 @@ def plot(

if min_max is None:
cum = _result.importance.values + baseline
min_max_margin = cum.ptp() * 0.15
min_max_margin = np.ptp(cum) * 0.15
temp_min_max[0] = np.min(
[
temp_min_max[0],
Expand Down
4 changes: 2 additions & 2 deletions python/dalex/dalex/aspect/_predict_triplot/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def plot(
line={"color": "#371ea3", "width": 1.5, "dash": "dot"},
)

min_x_imp, max_x_imp = np.Inf, -np.Inf
min_x_imp, max_x_imp = np.inf, -np.inf
for data in hierarchical_importance_dendrogram_plot["data"][::-1]:
data["xaxis"] = "x2"
data["hoverinfo"] = "text"
Expand All @@ -294,7 +294,7 @@ def plot(
max_x_imp = np.max([max_x_imp, np.max(data["x"])])
min_max_margin_imp = (max_x_imp - min_x_imp) * 0.15

min_x_clust, max_x_clust = np.Inf, -np.Inf
min_x_clust, max_x_clust = np.inf, -np.inf
for data in hierarchical_clustering_dendrogram_plot["data"]:
data["xaxis"] = "x3"
data["hoverinfo"] = "text"
Expand Down
4 changes: 2 additions & 2 deletions python/dalex/dalex/aspect/_predict_triplot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def plot_single_aspects_importance(
}
)

temp_min_max = [np.Inf, -np.Inf]
min_max_margin = _result.importance.values.ptp() * 0.15
temp_min_max = [np.inf, -np.inf]
min_max_margin = np.ptp(_result.importance.values) * 0.15
temp_min_max[0] = np.min(
[temp_min_max[0], _result.importance.values.min() - min_max_margin]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def plot(self,

# calculate y axis range to allow for fixedrange True
dl = _result_df['_yhat_'].to_numpy()
min_max_margin = dl.ptp() * 0.10
min_max_margin = np.ptp(dl) * 0.10
min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin]

is_x_numeric = False if geom == 'bars' else pd.api.types.is_numeric_dtype(_result_df['_x_'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def plot(self,
_global_checks.global_raise_objects_class(objects, self.__class__)

dl = _result_df.loc[_result_df.variable != '_baseline_', 'dropout_loss'].to_numpy()
min_max_margin = dl.ptp() * 0.15
min_max_margin = np.ptp(dl) * 0.15
min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin]

# take out full model
Expand Down
4 changes: 2 additions & 2 deletions python/dalex/dalex/predict_explanations/_break_down/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def plot(self,
vcolors = _theme.get_break_down_colors()

if min_max is None:
temp_min_max = [np.Inf, -np.Inf]
temp_min_max = [np.inf, -np.inf]
else:
temp_min_max = min_max

Expand Down Expand Up @@ -256,7 +256,7 @@ def plot(self,

if min_max is None:
cum = df.cumulative.values
min_max_margin = cum.ptp() * 0.15
min_max_margin = np.ptp(cum) * 0.15
temp_min_max[0] = np.min([temp_min_max[0], cum.min() - min_max_margin])
temp_min_max[1] = np.max([temp_min_max[1], cum.max() + min_max_margin])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def plot(self,

# calculate y axis range to allow for fixedrange True
dl = _result_df['_yhat_'].to_numpy()
min_max_margin = dl.ptp() * 0.10
min_max_margin = np.ptp(dl) * 0.10
min_max = [dl.min() - min_max_margin, dl.max() + min_max_margin]

# create _x_
Expand Down
4 changes: 2 additions & 2 deletions python/dalex/dalex/predict_explanations/_shap/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def plot(self,
vcolors = _theme.get_break_down_colors()

if min_max is None:
temp_min_max = [np.Inf, -np.Inf]
temp_min_max = [np.inf, -np.inf]
else:
temp_min_max = min_max

Expand Down Expand Up @@ -263,7 +263,7 @@ def plot(self,

if min_max is None:
cum = df.contribution.values + prediction_baseline
min_max_margin = cum.ptp() * 0.15
min_max_margin = np.ptp(cum) * 0.15
temp_min_max[0] = np.min([temp_min_max[0], cum.min() - min_max_margin])
temp_min_max[1] = np.max([temp_min_max[1], cum.max() + min_max_margin])

Expand Down
Loading