Example #1
0
def test_size_time_for_various_alphas(n, alpha_count):
    d = 7
    m = 3
    alphas = np.ones(alpha_count)
    A_tag = get_varying_d_data(d=d, n=n)

    ridgecv_mes = measure_method(
        RidgeCV(alphas=alphas, cv=m).fit, A_tag[:, :d], A_tag[:, d])
    ridge_boost_mes = measure_method(ridgecv_boost, A_tag, alphas, m,
                                     get_optimal_k_value(d))

    lassocv_mes = measure_method(
        LassoCV(alphas=alphas, cv=m).fit, A_tag[:, :d], A_tag[:, d])
    lasso_boost_mes = measure_method(lassocv_boost, A_tag, alphas, m,
                                     get_optimal_k_value(d))

    elasticcv_mes = measure_method(
        ElasticNetCV(alphas=alphas, cv=m, l1_ratio=RHO).fit, A_tag[:, :d],
        A_tag[:, d])
    elastic_boost_mes = measure_method(elasticcv_boost, A_tag, m, alphas, RHO,
                                       get_optimal_k_value(d))

    with open('SECOND_PERFORMANCE_TEST_RESULTS.txt', 'a+') as f:
        f.write("ridge,{n},{alpha_count},{duration}\n".format(
            n=n, alpha_count=alpha_count, duration=ridgecv_mes.duration))
        f.write("ridge_boost,{n},{alpha_count},{duration}\n".format(
            n=n, alpha_count=alpha_count, duration=ridge_boost_mes.duration))
        f.write("lasso,{n},{alpha_count},{duration}\n".format(
            n=n, alpha_count=alpha_count, duration=lassocv_mes.duration))
        f.write("lasso_boost,{n},{alpha_count},{duration}\n".format(
            n=n, alpha_count=alpha_count, duration=lasso_boost_mes.duration))
        f.write("elastic,{n},{alpha_count},{duration}\n".format(
            n=n, alpha_count=alpha_count, duration=elasticcv_mes.duration))
        f.write("elastic_boost,{n},{alpha_count},{duration}\n".format(
            n=n, alpha_count=alpha_count, duration=elastic_boost_mes.duration))
Example #2
0
def test_time_for_increasing_alphas(dataset, dataset_name, alpha_count):
    m = 3
    alphas = np.ones(alpha_count)
    A_tag = get_dataset(dataset)
    n, d_tag = A_tag.shape
    d = d_tag - 1
    ridgecv_mes = measure_method(
        RidgeCV(alphas=alphas, cv=m).fit, A_tag[:, :d], A_tag[:, d])
    ridge_boost_mes = measure_method(ridgecv_boost, A_tag, alphas, m,
                                     get_optimal_k_value(d))

    lassocv_mes = measure_method(
        LassoCV(alphas=alphas, cv=m).fit, A_tag[:, :d], A_tag[:, d])
    lasso_boost_mes = measure_method(lassocv_boost, A_tag, alphas, m,
                                     get_optimal_k_value(d))

    elasticcv_mes = measure_method(
        ElasticNetCV(alphas=alphas, cv=m, l1_ratio=RHO).fit, A_tag[:, :d],
        A_tag[:, d])
    elastic_boost_mes = measure_method(elasticcv_boost, A_tag, m, alphas, RHO,
                                       get_optimal_k_value(d))

    with open('THIRD_PERFORMANCE_TEST_RESULTS.txt', 'a+') as f:
        f.write("ridge,{dataset_name},{alpha_count},{duration}\n".format(
            dataset_name=dataset_name,
            alpha_count=alpha_count,
            duration=ridgecv_mes.duration))
        f.write("ridge_boost,{dataset_name},{alpha_count},{duration}\n".format(
            dataset_name=dataset_name,
            alpha_count=alpha_count,
            duration=ridge_boost_mes.duration))
        f.write("lasso,{dataset_name},{alpha_count},{duration}\n".format(
            dataset_name=dataset_name,
            alpha_count=alpha_count,
            duration=lassocv_mes.duration))
        f.write("lasso_boost,{dataset_name},{alpha_count},{duration}\n".format(
            dataset_name=dataset_name,
            alpha_count=alpha_count,
            duration=lasso_boost_mes.duration))
        f.write("elastic,{dataset_name},{alpha_count},{duration}\n".format(
            dataset_name=dataset_name,
            alpha_count=alpha_count,
            duration=elasticcv_mes.duration))
        f.write(
            "elastic_boost,{dataset_name},{alpha_count},{duration}\n".format(
                dataset_name=dataset_name,
                alpha_count=alpha_count,
                duration=elastic_boost_mes.duration))
Example #3
0
def test_linreg_datasets_accuracy(dataset):
    A_tag = get_dataset(dataset)
    (n, d_tag) = A_tag.shape
    d = d_tag - 1
    k = get_optimal_k_value(d)
    x_fast = linreg_boost(A_tag, m=1, k=k)[0]
    x = scipy.linalg.lstsq(A_tag[:, 0:d], A_tag[:, d])[0]
    err = np.linalg.norm(x - x_fast)
    print(err)
    print(err / np.linalg.norm(x))
Example #4
0
def test_lasso_datasets_accuracy(dataset):
    A_tag = get_dataset(dataset)
    (n, d_tag) = A_tag.shape
    alphas = (0.1, 1, 10, 100, 1000)
    d = d_tag - 1
    m = 64
    k = get_optimal_k_value(d)
    result_fast = lassocv_boost(A_tag, alphas=alphas, m=m, k=k)
    result = LassoCV(alphas=alphas, cv=m).fit(A_tag[:, 0:d], A_tag[:, d])
    err = np.linalg.norm(result_fast.coef_ - result.coef_)
    print(err)
    print(err / np.linalg.norm(result.coef_))
Example #5
0
def test_elastic_datasets_accuracy(dataset):
    A_tag = get_dataset(dataset)
    (n, d_tag) = A_tag.shape
    alphas = (0.1, 1, 10, 100, 1000)
    d = d_tag - 1
    m = 2
    k = get_optimal_k_value(d)
    rho = 0.5
    result_fast = elasticcv_boost(A_tag, alphas=alphas, m=m, k=k, rho=rho)
    result = ElasticNetCV(alphas=alphas, cv=m, l1_ratio=rho).fit(A_tag[:, 0:d], A_tag[:, d])
    err = np.linalg.norm(result_fast.coef_ - result.coef_)
    print(err)
    print(err / np.linalg.norm(result.coef_))
Example #6
0
def test_linreg_various_values(n, d):
    m = 64
    A_tag = get_varying_d_data(d, n)
    n, d_tag = A_tag.shape
    d = d_tag - 1
    linreg_mes = measure_method(scipy.linalg.lstsq, A_tag[:, :d], A_tag[:, d])
    linreg_boost_mes = measure_method(linreg_boost, A_tag, m,
                                      get_optimal_k_value(d))

    with open('LINREG_PERFORMANCE_TEST_D_VALUES_very_large.txt', 'a+') as f:
        f.write("linreg,{n},{d},{duration}\n".format(
            n=n, d=d, duration=linreg_mes.duration))
        f.write("linreg_boost,{n},{d},{duration}\n".format(
            n=n, d=d, duration=linreg_boost_mes.duration))