@@ -78,7 +78,8 @@ def __init__(
7878
7979 predict_fn , n_classes , _ = determine_classes (model , data , n_samples )
8080 if n_classes >= 3 :
81- raise Exception ("multiclass MorrisSensitivity not supported" )
81+ msg = "multiclass MorrisSensitivity not supported"
82+ raise Exception (msg )
8283 predict_fn = unify_predict_fn (predict_fn , data , 1 if n_classes == 2 else - 1 )
8384
8485 data , self .feature_names_in_ , self .feature_types_in_ = unify_data (
@@ -112,7 +113,7 @@ def __init__(
112113 )
113114
114115 unique_val_counts = np .zeros (len (self .feature_names_in_ ), dtype = np .int64 )
115- for col_idx , feature in enumerate (self .feature_names_in_ ):
116+ for col_idx , _feature in enumerate (self .feature_names_in_ ):
116117 X_col = data [:, col_idx ]
117118 unique_val_counts [col_idx ] = len (np .unique (X_col ))
118119
@@ -138,7 +139,7 @@ def explain_global(self, name=None):
138139 }
139140
140141 specific_data_dicts = []
141- for feat_idx , feature_name in enumerate (self .feature_names_in_ ):
142+ for feat_idx , _feature_name in enumerate (self .feature_names_in_ ):
142143 specific_data_dict = {
143144 "type" : "morris" ,
144145 "mu" : self .mu_ [feat_idx ],
@@ -193,7 +194,7 @@ def __init__(
193194 selector: A dataframe whose indices correspond to explanation entries.
194195 """
195196
196- super (MorrisExplanation , self ).__init__ (
197+ super ().__init__ (
197198 explanation_type ,
198199 internal_obj ,
199200 feature_names = feature_names ,
@@ -223,11 +224,10 @@ def visualize(self, key=None):
223224 data_dict = sort_take (
224225 data_dict , sort_fn = lambda x : - abs (x ), top_n = 15 , reverse_results = True
225226 )
226- title = "Morris Sensitivity<br>Convergence Index: {0 :.3f}" .format (
227+ title = "Morris Sensitivity<br>Convergence Index: {:.3f}" .format (
227228 data_dict ["convergence_index" ]
228229 )
229- figure = plot_horizontal_bar (data_dict , start_zero = True , title = title )
230- return figure
230+ return plot_horizontal_bar (data_dict , start_zero = True , title = title )
231231
232232 if self .explanation_type == "global" and key is not None :
233233 multi_html_template = r"""
@@ -282,10 +282,9 @@ def visualize(self, key=None):
282282 mu_star_conf = data_dict ["mu_star_conf" ],
283283 )
284284
285- html_str = multi_html_template .format (
285+ return multi_html_template .format (
286286 feature_name = self .feature_names [key ], analyses = analysis
287287 )
288- return html_str
289288
290289 return super ().visualize (key )
291290
@@ -312,9 +311,8 @@ def _soft_min_max(values, soft_add=1, soft_bounds=1):
312311
313312def _gen_problem_from_data (data , feature_names ):
314313 bounds = [_soft_min_max (data [:, i ]) for i , _ in enumerate (feature_names )]
315- problem = {
314+ return {
316315 "num_vars" : len (feature_names ),
317316 "names" : feature_names ,
318317 "bounds" : bounds ,
319318 }
320- return problem
0 commit comments