@@ -169,30 +169,38 @@ def baseline(X, y, t):
169169# following iterated selection process, the eta-cosine method will be much faster than
170170# the h-correlation method.
171171
172- X = rng .random ((3000 , 100 ))
172+ from timeit import repeat
173+
174+ X = rng .random ((3000 , 400 ))
173175y = rng .random ((3000 , 20 ))
174176
175- n_features_max = 30
177+ feature_num = np .arange (20 , 61 , step = 10 , dtype = int )
178+
176179
177- time_h = np .zeros (n_features_max , dtype = float )
178- time_eta = np .zeros (n_features_max , dtype = float )
179- for i in range (n_features_max ):
180- time_h [i ] = timeit (
181- f"s = FastCan({ i + 1 } , verbose=0).fit(X, y)" ,
182- number = 10 ,
180+ time_h = np .zeros (len (feature_num ), dtype = float )
181+ time_eta = np .zeros (len (feature_num ), dtype = float )
182+ for i , n_feats in enumerate (feature_num ):
183+ times_h = repeat (
184+ f"s = FastCan({ n_feats + 1 } , verbose=0).fit(X, y)" ,
185+ number = 1 ,
186+ repeat = 10 ,
183187 globals = globals (),
184188 )
185- time_eta [i ] = timeit (
186- f"s = FastCan({ i + 1 } , eta=True, verbose=0).fit(X, y)" ,
187- number = 10 ,
189+ time_h [i ] = np .median (times_h )
190+ times_eta = repeat (
191+ f"s = FastCan({ n_feats + 1 } , eta=True, verbose=0).fit(X, y)" ,
192+ number = 1 ,
193+ repeat = 10 ,
188194 globals = globals (),
189195 )
196+ time_eta [i ] = np .median (times_eta )
197+
190198
191- feature_num = np .arange (n_features_max , dtype = int ) + 1
192199plt .plot (feature_num , time_h , label = "h-correlation" )
193200plt .plot (feature_num , time_eta , label = r"$\eta$-cosine" )
194201plt .title ("Elapsed Time Comparison" )
195202plt .xlabel ("Number of Selected Features" )
196203plt .ylabel ("Elapsed Time (s)" )
204+ plt .xticks (feature_num )
197205plt .legend (loc = "lower right" )
198206plt .show ()
0 commit comments