You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: slise/slise.py
+51-47Lines changed: 51 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ def regression(
50
50
max_approx: float=1.15,
51
51
max_iterations: int=300,
52
52
debug: bool=False,
53
-
num_threads: int=-1,
53
+
num_threads: int=1,
54
54
) ->SliseRegression:
55
55
"""Use SLISE for robust regression
56
56
@@ -78,7 +78,7 @@ def regression(
78
78
max_approx (float, optional): Approximation ratio when selecting the next beta. Defaults to 1.15.
79
79
max_iterations (int, optional): Maximum number of OWL-QN iterations. Defaults to 300.
80
80
debug (bool, optional): Print debug statements each graduated optimisation step. Defaults to False.
81
-
num_threads (int, optional): The number of threadsto use for the optimisation. Defaults to -1.
81
+
num_threads (int, optional): The number of numba threads. Set to -1 to use numba defaults. Values >1 sometimes cause unexpectedly large overhead on some CPUs. Defaults to 1.
82
82
83
83
Returns:
84
84
SliseRegression: Object containing the regression result.
@@ -117,7 +117,7 @@ def explain(
117
117
max_approx: float=1.15,
118
118
max_iterations: int=300,
119
119
debug: bool=False,
120
-
num_threads: int=-1,
120
+
num_threads: int=1,
121
121
) ->SliseExplainer:
122
122
"""Use SLISE for explaining outcomes from black box models.
123
123
@@ -151,7 +151,7 @@ def explain(
151
151
max_approx (float, optional): Approximation ratio when selecting the next beta. Defaults to 1.15.
152
152
max_iterations (int, optional): Maximum number of OWL-QN iterations. Defaults to 300.
153
153
debug (bool, optional): Print debug statements each graduated optimisation step. Defaults to False.
154
-
num_threads (int, optional): The number of threadsto use for the optimisation. Defaults to -1.
154
+
num_threads (int, optional): The number of numba threads. Set to -1 to use numba defaults. Values >1 sometimes cause unexpectedly large overhead on some CPUs. Defaults to 1.
155
155
156
156
Returns:
157
157
SliseExplainer: Object containing the explanation.
@@ -194,7 +194,7 @@ def __init__(
194
194
max_approx: float=1.15,
195
195
max_iterations: int=300,
196
196
debug: bool=False,
197
-
num_threads: int=-1,
197
+
num_threads: int=1,
198
198
):
199
199
"""Use SLISE for robust regression.
200
200
@@ -218,7 +218,7 @@ def __init__(
218
218
max_approx (float, optional): Approximation ratio when selecting the next beta. Defaults to 1.15.
219
219
max_iterations (int, optional): Maximum number of OWL-QN iterations. Defaults to 300.
220
220
debug (bool, optional): Print debug statements each graduated optimisation step. Defaults to False.
221
-
num_threads (int, optional): The number of threadsto use for the optimisation. Defaults to -1.
221
+
num_threads (int, optional): The number of numba threads. Set to -1 to use numba defaults. Values >1 sometimes cause unexpectedly large overhead on some CPUs. Defaults to 1.
222
222
"""
223
223
assertepsilon>0.0, "`epsilon` must be positive!"
224
224
assertlambda1>=0.0, "`lambda1` must not be negative!"
@@ -293,26 +293,28 @@ def fit(
293
293
X=add_intercept_column(X)
294
294
# Initialisation
295
295
threads=set_threads(self.num_threads)
296
-
ifinitisNone:
297
-
alpha, beta=self.init_fn(X, Y, self.epsilon, self._weight)
298
-
else:
299
-
alpha, beta=initialise_fixed(init, X, Y, self.epsilon, self._weight)
300
-
# Optimisation
301
-
alpha=graduated_optimisation(
302
-
alpha=alpha,
303
-
X=X,
304
-
Y=Y,
305
-
epsilon=self.epsilon,
306
-
beta=beta,
307
-
lambda1=self.lambda1,
308
-
lambda2=self.lambda2,
309
-
weight=self._weight,
310
-
beta_max=self.beta_max,
311
-
max_approx=self.max_approx,
312
-
max_iterations=self.max_iterations,
313
-
debug=self.debug,
314
-
)
315
-
set_threads(threads)
296
+
try:
297
+
ifinitisNone:
298
+
alpha, beta=self.init_fn(X, Y, self.epsilon, self._weight)
299
+
else:
300
+
alpha, beta=initialise_fixed(init, X, Y, self.epsilon, self._weight)
301
+
# Optimisation
302
+
alpha=graduated_optimisation(
303
+
alpha=alpha,
304
+
X=X,
305
+
Y=Y,
306
+
epsilon=self.epsilon,
307
+
beta=beta,
308
+
lambda1=self.lambda1,
309
+
lambda2=self.lambda2,
310
+
weight=self._weight,
311
+
beta_max=self.beta_max,
312
+
max_approx=self.max_approx,
313
+
max_iterations=self.max_iterations,
314
+
debug=self.debug,
315
+
)
316
+
finally:
317
+
set_threads(threads)
316
318
self._alpha=alpha
317
319
ifself._normalise:
318
320
alpha2=self._scale.unscale_model(alpha)
@@ -575,7 +577,7 @@ def __init__(
575
577
max_approx: float=1.15,
576
578
max_iterations: int=300,
577
579
debug: bool=False,
578
-
num_threads: int=-1,
580
+
num_threads: int=1,
579
581
):
580
582
"""Use SLISE for explaining outcomes from black box models.
581
583
@@ -606,7 +608,7 @@ def __init__(
606
608
max_approx (float, optional): Approximation ratio when selecting the next beta. Defaults to 1.15.
607
609
max_iterations (int, optional): Maximum number of OWL-QN iterations. Defaults to 300.
608
610
debug (bool, optional): Print debug statements each graduated optimisation step. Defaults to False.
609
-
num_threads (int, optional): The number of threadsto use for the optimisation. Defaults to -1.
611
+
num_threads (int, optional): The number of numba threads. Set to -1 to use numba defaults. Values >1 sometimes cause unexpectedly large overhead on some CPUs. Defaults to 1.
610
612
"""
611
613
assertepsilon>0.0, "`epsilon` must be positive!"
612
614
assertlambda1>=0.0, "`lambda1` must not be negative!"
@@ -705,25 +707,27 @@ def explain(
705
707
X=self._X2-x[None, :]
706
708
Y=self._Y2-y
707
709
threads=set_threads(self.num_threads)
708
-
ifinitisNone:
709
-
alpha, beta=self.init_fn(X, Y, self.epsilon, self._weight)
710
-
else:
711
-
alpha, beta=initialise_fixed(init, X, Y, self.epsilon, self._weight)
712
-
alpha=graduated_optimisation(
713
-
alpha=alpha,
714
-
X=X,
715
-
Y=Y,
716
-
epsilon=self.epsilon,
717
-
beta=beta,
718
-
lambda1=self.lambda1,
719
-
lambda2=self.lambda2,
720
-
weight=self._weight,
721
-
beta_max=self.beta_max,
722
-
max_approx=self.max_approx,
723
-
max_iterations=self.max_iterations,
724
-
debug=self.debug,
725
-
)
726
-
set_threads(threads)
710
+
try:
711
+
ifinitisNone:
712
+
alpha, beta=self.init_fn(X, Y, self.epsilon, self._weight)
713
+
else:
714
+
alpha, beta=initialise_fixed(init, X, Y, self.epsilon, self._weight)
0 commit comments