Skip to content

Commit abf3dec

Browse files
committed
update from base ALE
1 parent af08975 commit abf3dec

2 files changed

Lines changed: 23 additions & 6 deletions

File tree

src/hidimstat/visualization/accumulated_local_effects.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def compute_ale_1d(
168168
confidence_interval=True,
169169
confidence_level=0.95,
170170
n_bootstraps=20,
171-
n_jobs=-1
171+
n_jobs=-1,
172172
):
173173
"""Compute the 1D Accumulated Local Effect for a single numerical feature.
174174
@@ -304,7 +304,9 @@ def _compute_ale_curve(X_sample):
304304
mask_low = x_sample != grid_values[0]
305305
mask_high = x_sample != grid_values[-1]
306306
X_low[mask_low, feature_idx] = grid_values[value_idx[mask_low] - 1]
307-
X_high[mask_high, feature_idx] = grid_values[value_idx[mask_high] + 1]
307+
X_high[mask_high, feature_idx] = grid_values[
308+
value_idx[mask_high] + 1
309+
]
308310

309311
local_effects_low = _predict_fn(
310312
estimator, X_sample[mask_low]
@@ -340,7 +342,10 @@ def _compute_ale_curve(X_sample):
340342

341343
# Center: subtract the sample-weighted mean
342344
ale_centers = (ale_curve[1:] + ale_curve[:-1]) / 2
343-
ale_curve -= np.sum(ale_centers * bin_counts[min_weight_bin:]) / bin_counts.sum()
345+
ale_curve -= (
346+
np.sum(ale_centers * bin_counts[min_weight_bin:])
347+
/ bin_counts.sum()
348+
)
344349

345350
return ale_curve
346351

test/visualization/test_accumulated_local_effects.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,12 @@ def test_compute_ale_1d_discrete(ale_test_data):
338338
# To test _bootstrap()
339339
with parallel_backend("threading"):
340340
result_bootstrap = compute_ale_1d(
341-
model, X, feature_idx=0, feature_type="categorical", confidence_interval=True, n_bootstraps=2
341+
model,
342+
X,
343+
feature_idx=0,
344+
feature_type="categorical",
345+
confidence_interval=True,
346+
n_bootstraps=2,
342347
)
343348

344349

@@ -351,10 +356,17 @@ def test_compute_ale_1d_discrete_error(ale_test_data):
351356
X_const[:, 0] = 7
352357

353358
with pytest.raises(ValueError, match="has fewer than 2 unique values"):
354-
compute_ale_1d(model, X_const, feature_idx=0, feature_type="categorical")
359+
compute_ale_1d(
360+
model, X_const, feature_idx=0, feature_type="categorical"
361+
)
355362
with pytest.raises(ValueError, match="must be strictly greater than"):
356363
compute_ale_1d(
357-
model, X, feature_idx=0, feature_type="categorical", confidence_interval=True, n_bootstraps=0
364+
model,
365+
X,
366+
feature_idx=0,
367+
feature_type="categorical",
368+
confidence_interval=True,
369+
n_bootstraps=0,
358370
)
359371

360372
with pytest.raises(

0 commit comments

Comments
 (0)