Skip to content

Commit 080bba0

Browse files
committed
step 10
1 parent 883304e commit 080bba0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

examples/plot_speed.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,36 +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))
173175
y = rng.random((3000, 20))
174176

175-
n_features_max = 30
177+
feature_num = np.arange(30, 71, step=10, dtype=int)
176178

177-
from timeit import repeat
178179

179-
time_h = np.zeros(n_features_max, dtype=float)
180-
time_eta = np.zeros(n_features_max, dtype=float)
181-
for i in range(n_features_max):
180+
time_h = np.zeros(len(feature_num), dtype=float)
181+
time_eta = np.zeros(len(feature_num), dtype=float)
182+
for i, n_feat in enumerate(feature_num):
182183
times_h = repeat(
183-
f"s = FastCan({i + 1}, verbose=0).fit(X, y)",
184+
f"s = FastCan({n_feat + 1}, verbose=0).fit(X, y)",
184185
number=1,
185186
repeat=10,
186187
globals=globals(),
187188
)
188189
time_h[i] = np.median(times_h)
189190
times_eta = repeat(
190-
f"s = FastCan({i + 1}, eta=True, verbose=0).fit(X, y)",
191+
f"s = FastCan({n_feat + 1}, eta=True, verbose=0).fit(X, y)",
191192
number=1,
192193
repeat=10,
193194
globals=globals(),
194195
)
195196
time_eta[i] = np.median(times_eta)
196197

197-
feature_num = np.arange(n_features_max, dtype=int) + 1
198+
198199
plt.plot(feature_num, time_h, label="h-correlation")
199200
plt.plot(feature_num, time_eta, label=r"$\eta$-cosine")
200201
plt.title("Elapsed Time Comparison")
201202
plt.xlabel("Number of Selected Features")
202203
plt.ylabel("Elapsed Time (s)")
204+
plt.xticks(feature_num)
203205
plt.legend(loc="lower right")
204206
plt.show()

0 commit comments

Comments
 (0)