Beispiel #1
0
                    model,
                    X,
                    y,
                    None,
                    None,
                    monitor,
                    max_evals=20,
                    tol=tol,
                    alphas=alphas)
    elif algo_name == 'random_search' or algo_name == 'bayesian':
        hyperopt_wrapper(algo,
                         criterion,
                         model,
                         X,
                         y,
                         alpha_min,
                         alpha_max,
                         monitor,
                         max_evals=20,
                         tol=tol,
                         method=algo_name,
                         size_space=2)
    else:
        1 / 0
    dict_monitor[algo_name] = monitor

min_objs = np.infty
for monitor in dict_monitor.values():
    monitor.objs = np.array(monitor.objs)
    min_objs = min(min_objs, monitor.objs.min())

scaling_factor = (y @ y) / len(y)
Beispiel #2
0
            n_alphas = 100
        p_alphas = np.geomspace(1, p_alpha_min, n_alphas)
        alphas = alpha_max * p_alphas
        reg = LassoCV(cv=kf,
                      verbose=True,
                      tol=tol,
                      fit_intercept=False,
                      alphas=alphas,
                      max_iter=max_iter).fit(X, y)
        reg.score(X, y)
        objs = reg.mse_path_.mean(axis=1)
        log_alphas = np.log(alphas)
    else:
        hyperopt_wrapper(algo,
                         cross_val_criterion,
                         model,
                         X,
                         y,
                         np.log(alpha_max * p_alpha_min),
                         np.log(alpha_max),
                         monitor,
                         max_evals=10,
                         method=algorithm,
                         size_space=1)
        objs = np.array(monitor.objs)
        log_alphas = np.array(monitor.log_alphas)
    log_alphas -= np.log(alpha_max)
    np.save("results/log_alphas_%s" % algorithm, log_alphas)
    np.save("results/objs_%s" % algorithm, objs)
    print('%s finished' % algorithm)
Beispiel #3
0
            optimizer = LineSearch(n_outer=25, verbose=True, tol=tol)
        grad_search(
            algo, cross_val_criterion, model, optimizer, X, y, log_alpha0,
            monitor)

    elif algorithm.startswith('grid_search'):
        if algorithm == 'grid_search10':
            n_alphas = 5
        else:
            n_alphas = 30
        p_alphas = np.geomspace(1, p_alpha_min, n_alphas)
        alphas = alpha_max * p_alphas
        log_alphas = np.log(alphas)
        grid_alphas = [i for i in itertools.product(log_alphas, log_alphas)]

        grid_search(
            algo, cross_val_criterion, model, X, y, None, None, monitor,
            log_alphas=grid_alphas)
    else:
        hyperopt_wrapper(
            algo, cross_val_criterion, model, X, y, log_alpha_min,
            log_alpha_max, monitor, max_evals=max_evals,
            method=algorithm, size_space=2)

    objs = np.array(monitor.objs)
    log_alphas = np.array(monitor.log_alphas)
    log_alphas -= np.log(alpha_max)
    np.save("results/%s_log_alphas_%s_enet" % (dataset, algorithm), log_alphas)
    np.save("results/%s_objs_%s_enet" % (dataset, algorithm), objs)
    print('%s finished' % algorithm)
Beispiel #4
0
                    criterion,
                    model,
                    X,
                    y,
                    alpha_min,
                    alpha_max,
                    monitor,
                    max_evals=20,
                    tol=tol)
    elif algo_name == 'random_search':
        hyperopt_wrapper(algo,
                         criterion,
                         model,
                         X,
                         y,
                         alpha_min,
                         alpha_max,
                         monitor,
                         max_evals=20,
                         tol=tol,
                         method='random',
                         size_space=1)
    dict_monitor[algo_name] = monitor

min_objs = np.infty
for monitor in dict_monitor.values():
    monitor.objs = np.array(monitor.objs)
    min_objs = min(min_objs, monitor.objs.min())

scaling_factor = (y @ y) / len(y)
plt.figure()
for monitor in dict_monitor.values():
Beispiel #5
0
        p_alphas = np.geomspace(1, p_alpha_min, n_alphas)
        alphas = alpha_max * p_alphas
        reg = LassoCV(cv=kf,
                      verbose=True,
                      tol=tol,
                      fit_intercept=False,
                      alphas=alphas,
                      max_iter=max_iter).fit(X, y)
        reg.score(X, y)
        objs = reg.mse_path_.mean(axis=1)
        log_alphas = np.log(alphas / alpha_max)
    else:
        hyperopt_wrapper(algo,
                         cross_val_criterion,
                         model,
                         X,
                         y,
                         alpha_max * p_alpha_min,
                         alpha_max,
                         monitor,
                         max_evals=10,
                         method=algorithm,
                         size_space=1,
                         tol=tol,
                         random_state=4)
        objs = np.array(monitor.objs)
        log_alphas = np.log(np.array(monitor.alphas) / alpha_max)
    np.save("results/log_alphas_%s" % algorithm, log_alphas)
    np.save("results/objs_%s" % algorithm, objs)
    print('%s finished' % algorithm)