def lasso(): """Fit Lasso.""" print("Fitting LAS...", end=" ", flush=True) time.sleep(SLEEP) t0 = time.time() ls = Lasso() ls.fit(X, y) print_time(t0, "Done", end="")
def knn(): """Fit KNN.""" print("Fitting KNN...", end=" ", flush=True) time.sleep(SLEEP) t0 = time.time() knn = KNeighborsRegressor() knn.fit(X, y) print_time(t0, "Done", end="")
def ensemble(): """Fit ensemble.""" print("Fitting ENS...", end=" ", flush=True) time.sleep(SLEEP) t0 = time.time() ens = build_ensemble(shuffle=False, folds=2) ens.fit(X, y) print_time(t0, "Done", end="")
def elasticnet(): """Fit Elastic Net.""" print("Fitting ELN...", end=" ", flush=True) time.sleep(SLEEP) t0 = time.time() ls = Lasso() ls.fit(X, y) print_time(t0, "Done", end="")
name = e.__class__.__name__ e = clone(e) t0 = perf_counter() e.fit(X, y) t1 = perf_counter() - t0 times[n][name].append(t1) print('%s (%i) : %6.2fs |' % (name, n, t1), end=" ", flush=True) print() print() print_time(ts, "Benchmark done") if PLOT: try: import matplotlib.pyplot as plt plt.ion() print("Plotting results...", end=" ", flush=True) plt.figure(figsize=(8, 8)) x = range(STEP, MAX + STEP, STEP) cm = [ plt.cm.rainbow(i) for i in np.linspace(0, 1.0, int(3 * len(cores))) ]
@profile def elasticnet(): """Fit Elastic Net.""" print("Fitting ELN...", end=" ", flush=True) time.sleep(SLEEP) t0 = time.time() ls = Lasso() ls.fit(X, y) print_time(t0, "Done", end="") if __name__ == '__main__': X, y = make_friedman1(MAX, COLS) print("\nML-ENSEMBLE\n") print("Benchmark of ML-ENSEMBLE memory profile against " "Scikit-learn estimators.\n" "Data shape: (%i, %i)\n" "Data size: %i MB\n" % (MAX, COLS, np.ceil(X.nbytes / 1e+6))) ts = time.time() lasso() knn() ensemble() elasticnet() print_time(ts, "\nProfiling complete.")