2424 "batch_size" : [
2525 Interval (Integral , 1 , None , closed = "left" ),
2626 ],
27+ "verbose" : ["verbose" ],
2728 },
2829 prefer_skip_nested_validation = False ,
2930)
30- def minibatch (X , y , n_features_to_select = 1 , batch_size = 1 ):
31+ def minibatch (X , y , n_features_to_select = 1 , batch_size = 1 , verbose = 1 ):
3132 """FastCan selection with mini batches.
3233
3334 It is suitable for selecting a very large number of features
@@ -52,6 +53,9 @@ def minibatch(X, y, n_features_to_select=1, batch_size=1):
5253 The number of features in a mini-batch.
5354 It is recommended that batch_size be less than n_samples.
5455
56+ verbose : int, default=1
57+ The verbosity level.
58+
5559 Returns
5660 -------
5761 indices : ndarray of shape (n_features_to_select,), dtype=int
@@ -62,7 +66,7 @@ def minibatch(X, y, n_features_to_select=1, batch_size=1):
6266 >>> from fastcan import minibatch
6367 >>> X = [[1, 1, 0], [0.01, 0, 0], [-1, 0, 1], [0, 0, 0]]
6468 >>> y = [1, 0, -1, 0]
65- >>> indices = minibatch(X, y, 3, batch_size=2)
69+ >>> indices = minibatch(X, y, 3, batch_size=2, verbose=0 )
6670 >>> print(f"Indices: {indices}")
6771 Indices: [0 1 2]
6872 """
@@ -81,15 +85,14 @@ def minibatch(X, y, n_features_to_select=1, batch_size=1):
8185
8286 n_threads = _openmp_effective_n_threads ()
8387
84- output_arange = np .r_ [np .arange (n_outputs , step = batch_size , dtype = int ), n_outputs ]
8588 n_to_select_split = np .diff (
8689 np .linspace (
87- 0 , n_features_to_select , num = output_arange . size , endpoint = True , dtype = int
90+ 0 , n_features_to_select , num = n_outputs + 1 , endpoint = True , dtype = int
8891 )
8992 )
9093 indices_select = np .zeros (0 , dtype = int )
91- for i in range (n_to_select_split . size ):
92- y_i = y [:, output_arange [ i ] : output_arange [ i + 1 ] ]
94+ for i in range (n_outputs ):
95+ y_i = y [:, i ]
9396 batch_split_i = np .diff (
9497 np .r_ [
9598 np .arange (n_to_select_split [i ], step = batch_size , dtype = int ),
@@ -122,4 +125,10 @@ def minibatch(X, y, n_features_to_select=1, batch_size=1):
122125 scores = scores ,
123126 )
124127 indices_select = np .r_ [indices_select , indices ]
128+ if verbose == 1 :
129+ print (
130+ f"Progress: { indices_select .size } /{ n_features_to_select } " , end = "\r "
131+ )
132+ if verbose == 1 :
133+ print ()
125134 return indices_select
0 commit comments