Skip to content

Commit 635a23d

Browse files
committed
format document
1 parent 61dcbda commit 635a23d

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

src/hidimstat/marginal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .leave_one_covariate_in import LeaveOneCovariateIn
22

3-
__all__ = ["LeaveOneCovariateIn"]
3+
__all__ = ["LeaveOneCovariateIn"]

src/hidimstat/marginal/leave_one_covariate_in.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353
def fit(self, X, y, features_groups=None):
5454
"""
5555
Fit the marginal information variable importance model.
56-
56+
5757
Parameters
5858
----------
5959
X : array-like of shape (n_samples, n_features)
@@ -64,7 +64,7 @@ def fit(self, X, y, features_groups=None):
6464
A dictionary where the keys are group identifiers and the values are lists
6565
of feature indices or names for each group. If None, each feature is
6666
treated as its own group.
67-
67+
6868
Returns
6969
-------
7070
self : object
@@ -84,14 +84,14 @@ def predict(self, X):
8484
"""
8585
Compute the predictions after perturbation of the data for each group of
8686
features.
87-
87+
8888
Parameters
8989
----------
9090
X : array-like of shape (n_samples, n_features)
9191
The input samples.
9292
y : array-like of shape (n_samples,)
9393
The target values.
94-
94+
9595
Returns
9696
-------
9797
out : array-like of shape (n_features_groups, n_samples)
@@ -102,22 +102,26 @@ def predict(self, X):
102102

103103
# Parallelize the computation of the importance scores for each group
104104
out_list = Parallel(n_jobs=self.n_jobs)(
105-
delayed(self._joblib_predict_one_features_group)(X_, features_group_id, features_groups_ids)
106-
for features_group_id, features_groups_ids in enumerate(self._features_groups_ids)
105+
delayed(self._joblib_predict_one_features_group)(
106+
X_, features_group_id, features_groups_ids
107+
)
108+
for features_group_id, features_groups_ids in enumerate(
109+
self._features_groups_ids
110+
)
107111
)
108112
return np.array(out_list)
109113

110114
def importance(self, X, y):
111115
"""
112116
Compute the marginal importance scores for each group of features.
113-
117+
114118
Parameters
115119
----------
116120
X : array-like of shape (n_samples, n_features)
117121
The input samples.
118122
y : array-like of shape (n_samples,)
119123
The target values.
120-
124+
121125
Returns
122126
-------
123127
out_dict : dict
@@ -154,7 +158,7 @@ def importance(self, X, y):
154158
def fit_importance(self, X, y, cv, features_groups=None):
155159
"""
156160
Fits the model to the data and computes feature importance.
157-
161+
158162
Parameters
159163
----------
160164
X : array-like of shape (n_samples, n_features)
@@ -167,7 +171,7 @@ def fit_importance(self, X, y, cv, features_groups=None):
167171
A dictionary where the keys are group identifiers and the values are lists
168172
of feature indices or names for each group. If None, each feature is
169173
treated as its own group.
170-
174+
171175
Returns
172176
-------
173177
importance : array-like
@@ -195,7 +199,7 @@ def fit_importance(self, X, y, cv, features_groups=None):
195199
def _joblib_fit_one_features_group(self, X, y, features_group_ids):
196200
"""
197201
Helper function to fit a univariate model for a single group.
198-
202+
199203
Parameters
200204
----------
201205
X : array-like of shape (n_samples, n_features)
@@ -204,19 +208,23 @@ def _joblib_fit_one_features_group(self, X, y, features_group_ids):
204208
The target values.
205209
features_group_ids : array-like
206210
The indices of features belonging to this group.
207-
211+
208212
Returns
209213
-------
210214
object
211215
The fitted univariate model for this group.
212216
"""
213217
univariate_model = clone(self.estimator)
214-
return univariate_model.fit(X[:, features_group_ids].reshape(-1, len(features_group_ids)), y)
218+
return univariate_model.fit(
219+
X[:, features_group_ids].reshape(-1, len(features_group_ids)), y
220+
)
215221

216-
def _joblib_predict_one_features_group(self, X, index_features_group, features_group_ids):
222+
def _joblib_predict_one_features_group(
223+
self, X, index_features_group, features_group_ids
224+
):
217225
"""
218226
Helper function to predict for a single group.
219-
227+
220228
Parameters
221229
----------
222230
X : array-like of shape (n_samples, n_features)
@@ -225,13 +233,13 @@ def _joblib_predict_one_features_group(self, X, index_features_group, features_g
225233
The index of the group in _list_univariate_model.
226234
features_group_ids : array-like
227235
The indices of features belonging to this group.
228-
236+
229237
Returns
230238
-------
231239
float
232240
The prediction score for this group.
233241
"""
234-
y_pred_loci = getattr(self._list_univariate_model[index_features_group], self.method)(
235-
X[:, features_group_ids].reshape(-1, len(features_group_ids))
236-
)
237-
return y_pred_loci
242+
y_pred_loci = getattr(
243+
self._list_univariate_model[index_features_group], self.method
244+
)(X[:, features_group_ids].reshape(-1, len(features_group_ids)))
245+
return y_pred_loci

test/marginal/test_leave_one_covariate_in.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def configure_linear_categorial_loci(X, y):
2424
and each row a sample.
2525
y : array-like of shape (n_samples,)
2626
Target variable array.
27-
27+
2828
Returns
2929
-------
3030
importance : array-like
3131
Array containing importance scores for each feature.
3232
Higher values indicate greater feature importance in predicting
3333
the target variable.
34-
34+
3535
Notes
3636
-----
3737
The function performs the following steps:
@@ -343,4 +343,4 @@ def test_groups_warning(self, data_generator):
343343
UserWarning,
344344
match="The number of features in X: 200 differs from the number of features for which importance is computed: 4",
345345
):
346-
loci.importance(X, y)
346+
loci.importance(X, y)

0 commit comments

Comments
 (0)