8000 [MRG+1] add docs that C can receive array in RandomizedLogisticRegression by pianomania · Pull Request #6537 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG+1] add docs that C can receive array in RandomizedLogisticRegression #6537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
0