24
24
"batch_size" : [
25
25
Interval (Integral , 1 , None , closed = "left" ),
26
26
],
27
+ "verbose" : ["verbose" ],
27
28
},
28
29
prefer_skip_nested_validation = False ,
29
30
)
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 ):
31
32
"""FastCan selection with mini batches.
32
33
33
34
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):
52
53
The number of features in a mini-batch.
53
54
It is recommended that batch_size be less than n_samples.
54
55
56
+ verbose : int, default=1
57
+ The verbosity level.
58
+
55
59
Returns
56
60
-------
57
61
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):
62
66
>>> from fastcan import minibatch
63
67
>>> X = [[1, 1, 0], [0.01, 0, 0], [-1, 0, 1], [0, 0, 0]]
64
68
>>> 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 )
66
70
>>> print(f"Indices: {indices}")
67
71
Indices: [0 1 2]
68
72
"""
@@ -81,15 +85,14 @@ def minibatch(X, y, n_features_to_select=1, batch_size=1):
81
85
82
86
n_threads = _openmp_effective_n_threads ()
83
87
84
- output_arange = np .r_ [np .arange (n_outputs , step = batch_size , dtype = int ), n_outputs ]
85
88
n_to_select_split = np .diff (
86
89
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
88
91
)
89
92
)
90
93
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 ]
93
96
batch_split_i = np .diff (
94
97
np .r_ [
95
98
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):
122
125
scores = scores ,
123
126
)
124
127
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 ()
125
134
return indices_select
0 commit comments