Beispiel #1
0
def test_lasso_selection_sweep():
    """Tests uoi_selection_sweep for UoI_Lasso."""

    # toy data
    X = np.array([[-1, 2, 3], [4, 1, -7], [1, 3, 1], [4, 3, 12], [8, 11, 2]])
    beta = np.array([1, 4, 2])
    y = np.dot(X, beta)

    # toy regularization
    reg_param_values = [{'alpha': 1.0}, {'alpha': 2.0}]
    lasso1 = Lasso(alpha=1.0, fit_intercept=True, normalize=True)
    lasso2 = Lasso(alpha=2.0, fit_intercept=True, normalize=True)
    lasso = UoI_Lasso(fit_intercept=True, normalize=True)

    coefs = lasso.uoi_selection_sweep(X, y, reg_param_values)
    lasso1.fit(X, y)
    lasso2.fit(X, y)

    assert np.allclose(coefs[0], lasso1.coef_)
    assert np.allclose(coefs[1], lasso2.coef_)
Beispiel #2
0
def test_lasso_selection_sweep():
    """Tests uoi_selection_sweep for UoI_Lasso."""

    # toy data
    X = np.array([[-1, 2, 3], [4, 1, -7], [1, 3, 1], [4, 3, 12], [8, 11, 2]],
                 dtype=float)
    beta = np.array([1, 4, 2], dtype=float)
    y = np.dot(X, beta)

    # toy regularization
    reg_param_values = [{'alpha': 1.0}, {'alpha': 2.0}]
    lasso = UoI_Lasso(fit_intercept=True, warm_start=False)
    lasso1 = Lasso(alpha=1.0, fit_intercept=True, max_iter=lasso.max_iter)
    lasso2 = Lasso(alpha=2.0, fit_intercept=True, max_iter=lasso.max_iter)
    lasso.output_dim = 1

    coefs = lasso.uoi_selection_sweep(X, y, reg_param_values)
    lasso1.fit(X, y)
    lasso2.fit(X, y)

    assert np.allclose(coefs[0], lasso1.coef_)
    assert np.allclose(coefs[1], lasso2.coef_)