Skip to content

Commit 9b7dfd6

Browse files
committed
minor optimizations in many places
1 parent af37b4a commit 9b7dfd6

File tree

7 files changed

+286
-140
lines changed

7 files changed

+286
-140
lines changed

python/interpret-core/interpret/glassbox/_ebm/_bin.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414

1515

1616
_none_list = [None]
17-
_make_non_list = _none_list.__mul__
17+
_make_none_list = _none_list.__mul__
1818
_none_ndarray = np.array(None)
1919
_repeat_none = repeat(None)
2020
_repeat_dict = repeat(dict)
2121
_make_new_lists = map(list, repeat(tuple()))
2222
_sub_one = (-1).__add__
23+
_sub_two = (-2).__add__
2324
_eq_getter = attrgetter("__eq__")
2425
_flags_getter = attrgetter("flags")
2526
_continuous_getter = attrgetter("c_contiguous")
@@ -41,8 +42,6 @@ def eval_terms(X, n_samples, feature_names_in, feature_types_in, bins, term_feat
4142
# would be [(0), (1), (2), (3), (1, 3), (4)]. More complicated pair/triples return even more randomized ordering.
4243
# For additive models the results can be processed in any order, so this imposes no penalities on us.
4344

44-
_log.info("eval_terms")
45-
4645
# Flatten the term_features array to make one entry per feature within each term
4746
# each item in the list contains placeholders for the binned array that we need
4847
# to complete the term. We fill these with None initially. At the end of the array
@@ -55,7 +54,7 @@ def eval_terms(X, n_samples, feature_names_in, feature_types_in, bins, term_feat
5554
zip(
5655
map(
5756
add,
58-
map(_make_non_list, map(len, term_features)),
57+
map(_make_none_list, map(len, term_features)),
5958
map(list, zip(count())),
6059
)
6160
),
@@ -76,8 +75,8 @@ def eval_terms(X, n_samples, feature_names_in, feature_types_in, bins, term_feat
7675
map(
7776
min,
7877
zip(
79-
map((-1).__add__, map(len, all_bin_levels2)),
80-
map((-2).__add__, map(len, all_requirements)),
78+
map(_sub_one, map(len, all_bin_levels2)),
79+
map(_sub_two, map(len, all_requirements)),
8180
),
8281
)
8382
)
@@ -182,7 +181,7 @@ def eval_terms(X, n_samples, feature_names_in, feature_types_in, bins, term_feat
182181
map(_eq_getter, request_feature_idxs),
183182
map(bins.__getitem__, request_feature_idxs),
184183
map(len, map(bins.__getitem__, request_feature_idxs)),
185-
map(_make_non_list, map(len, map(bins.__getitem__, request_feature_idxs))),
184+
map(_make_none_list, map(len, map(bins.__getitem__, request_feature_idxs))),
186185
map(
187186
waiting.__getitem__,
188187
zip(request_feature_idxs, map(id, map(_itemgetter2, col1))),
@@ -278,13 +277,13 @@ def eval_terms(X, n_samples, feature_names_in, feature_types_in, bins, term_feat
278277
def ebm_predict_scores(
279278
X,
280279
n_samples,
280+
init_score,
281281
feature_names_in,
282282
feature_types_in,
283283
bins,
284284
intercept,
285285
term_scores,
286286
term_features,
287-
init_score=None,
288287
):
289288
sample_scores = (
290289
np.full(

0 commit comments

Comments
 (0)