Skip to content
11 changes: 10 additions & 1 deletion sklearn/linear_model/randomized_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ def _randomized_logistic(X, y, weights, mask, C=1., verbose=False,
X *= (1 - weights)

C = np.atleast_1d(np.asarray(C, dtype=np.float64))
if C.ndim > 1:
raise ValueError("C should be 1-dimensional array-like, "
"but got a {}-dimensional array-like instead: {}."
.format(C.ndim, C))

scores = np.zeros((X.shape[1], len(C)), dtype=np.bool)

for this_C, this_scores in zip(C, scores.T):
Expand Down Expand Up @@ -381,8 +386,12 @@ class RandomizedLogisticRegression(BaseRandomizedLinearModel):

Parameters
----------
C : float, optional, default=1
C : float or array-like of shape [n_reg_parameter], optional, default=1
The regularization parameter C in the LogisticRegression.
When C is an array, fit will take each regularization parameter in C
one by one for LogisticRegression and store results for each one
in ``all_scores_``, where columns and rows represent corresponding
reg_parameters and features.

scaling : float, optional, default=0.5
The s parameter used to randomly scale the penalty of different
Expand Down
3 changes: 3 additions & 0 deletions sklearn/linear_model/tests/test_randomized_l1.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def test_randomized_logistic():
feature_scores = clf.fit(X, y).scores_
assert_array_equal(np.argsort(F), np.argsort(feature_scores))

clf = RandomizedLogisticRegression(verbose=False, C=[[1., 0.5]])
assert_raises(ValueError, clf.fit, X, y)


def test_randomized_logistic_sparse():
# Check randomized sparse logistic regression on sparse data
Expand Down