Skip to content

Commit

Permalink
Merge branch 'master' into feature/interaction_plot_improvment
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-vignal committed Jul 4, 2024
2 parents a467eaa + b568987 commit b350f12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions shapash/explainer/smart_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,8 @@ def plot_scatter(
val_inter = feature_values_max - feature_values_min
from sklearn.neighbors import KernelDensity

feature_np = np.array(feature_values_array)[:, None]
median_value = np.nanmedian(feature_np)
feature_np = np.where(np.isnan(feature_np), median_value, feature_np)
feature_np = np.array(feature_values_array)
feature_np = feature_np[~np.isnan(feature_np)][:, None]
kde = KernelDensity(bandwidth=val_inter / 100, kernel="epanechnikov").fit(feature_np)
xs = np.linspace(feature_values_min, feature_values_max, 1000)
log_dens = kde.score_samples(xs[:, None])
Expand Down Expand Up @@ -3708,9 +3707,20 @@ def _prediction_regression_plot(
if len(y_target) > 500:
lower_quantile = y_target.iloc[:, 0].quantile(0.005)
upper_quantile = y_target.iloc[:, 0].quantile(0.995)
y_target = y_target.iloc[:, 0][
y_target_tmp = y_target.iloc[:, 0][
(y_target.iloc[:, 0] > lower_quantile) & (y_target.iloc[:, 0] < upper_quantile)
]
if len(y_target_tmp) > 0.95 * len(y_target):
y_target = y_target_tmp
else:
y_target_tmp = y_target.iloc[:, 0][(y_target.iloc[:, 0] < upper_quantile)]
if len(y_target_tmp) > 0.95 * len(y_target):
y_target = y_target_tmp
else:
y_target_tmp = y_target.iloc[:, 0][(y_target.iloc[:, 0] > lower_quantile)]
if len(y_target_tmp) > 0.95 * len(y_target):
y_target = y_target_tmp

y_target_values = y_target.values.flatten()

y_pred = self.explainer.y_pred.loc[y_target.index]
Expand All @@ -3727,9 +3737,8 @@ def _prediction_regression_plot(
val_inter = feature_values_max - feature_values_min
from sklearn.neighbors import KernelDensity

feature_np = np.array(feature_values_array)[:, None]
median_value = np.nanmedian(feature_np)
feature_np = np.where(np.isnan(feature_np), median_value, feature_np)
feature_np = np.array(feature_values_array)
feature_np = feature_np[~np.isnan(feature_np)][:, None]
kde = KernelDensity(bandwidth=val_inter / 300, kernel="epanechnikov").fit(feature_np)
xs = np.linspace(feature_values_min, feature_values_max, 1000)
log_dens = kde.score_samples(xs[:, None])
Expand Down
4 changes: 2 additions & 2 deletions shapash/webapp/smart_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import copy
import random
import re
from math import log10
from math import isfinite, log10

import dash
import dash_bootstrap_components as dbc
Expand Down Expand Up @@ -193,7 +193,7 @@ def init_data(self, rows=None):
typ = self.dataframe[col].dtype
if typ == float:
std = self.dataframe[col].std()
if std != 0:
if isfinite(std) and std != 0:
digit = max(round(log10(1 / std) + 1) + 2, 0)
self.round_dataframe[col] = self.dataframe[col].map(f"{{:.{digit}f}}".format).astype(float)

Expand Down

0 comments on commit b350f12

Please sign in to comment.