Skip to content

Commit f952e43

Browse files
pianomaniaagramfort
authored andcommitted
[MRG+1] add docs that C can receive array in RandomizedLogisticRegression (scikit-learn#6537)
* doc: state that parameter C can receive an array * add more details in doc, and check the dim of C * doc: state that parameter C can receive an array * add more details in doc, and check the dim of C * a little modification * minor modifications and make line length less than 79 characters * remove the backslash and correct typos * meet PEP8's E128 requirement * use .format and add a test
1 parent 676e863 commit f952e43

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sklearn/linear_model/randomized_l1.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,11 @@ def _randomized_logistic(X, y, weights, mask, C=1., verbose=False,
354354
X *= (1 - weights)
355355

356356
C = np.atleast_1d(np.asarray(C, dtype=np.float64))
357+
if C.ndim > 1:
358+
raise ValueError("C should be 1-dimensional array-like, "
359+
"but got a {}-dimensional array-like instead: {}."
360+
.format(C.ndim, C))
361+
357362
scores = np.zeros((X.shape[1], len(C)), dtype=np.bool)
358363

359364
for this_C, this_scores in zip(C, scores.T):
@@ -381,8 +386,12 @@ class RandomizedLogisticRegression(BaseRandomizedLinearModel):
381386
382387
Parameters
383388
----------
384-
C : float, optional, default=1
389+
C : float or array-like of shape [n_reg_parameter], optional, default=1
385390
The regularization parameter C in the LogisticRegression.
391+
When C is an array, fit will take each regularization parameter in C
392+
one by one for LogisticRegression and store results for each one
393+
in ``all_scores_``, where columns and rows represent corresponding
394+
reg_parameters and features.
386395
387396
scaling : float, optional, default=0.5
388397
The s parameter used to randomly scale the penalty of different

sklearn/linear_model/tests/test_randomized_l1.py

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def test_randomized_logistic():
100100
feature_scores = clf.fit(X, y).scores_
101101
assert_array_equal(np.argsort(F), np.argsort(feature_scores))
102102

103+
clf = RandomizedLogisticRegression(verbose=False, C=[[1., 0.5]])
104+
assert_raises(ValueError, clf.fit, X, y)
105+
103106

104107
def test_randomized_logistic_sparse():
105108
# Check randomized sparse logistic regression on sparse data

0 commit comments

Comments
 (0)