Skip to content

Commit 87b4784

Browse files
committed
Merge pull request scikit-learn#4010 from MechCoder/sparse_bug
[MRG] FIX: Bug in sparse coordinate solver in lazy centering
2 parents d65d8c4 + 2690193 commit 87b4784

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/whats_new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ Bug fixes
227227
:class:`cluster.AgglomerativeClustering` (and friends).
228228
This has been fixed By `Manoj Kumar`_
229229

230+
- Fix lazy centering of data in :func:`linear_model.enet_path` and
231+
:func:`linear_model.lasso_path`. It was centered around one. It has
232+
been changed to be centred around the origin. By `Manoj Kumar`_
233+
230234
API changes summary
231235
-------------------
232236

sklearn/linear_model/coordinate_descent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
451451
# to be passed to the CD solver.
452452
X_sparse_scaling = params['X_mean'] / params['X_std']
453453
else:
454-
X_sparse_scaling = np.ones(n_features)
454+
X_sparse_scaling = np.zeros(n_features)
455455

456456
X, y, X_mean, y_mean, X_std, precompute, Xy = \
457457
_pre_fit(X, y, Xy, precompute, normalize, fit_intercept, copy=False)

sklearn/linear_model/tests/test_coordinate_descent.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,18 @@ def test_enet_path_positive():
585585
assert_true(np.all(pos_path_coef >= 0))
586586

587587

588+
def test_sparse_dense_descent_paths():
589+
"""
590+
Test that dense and sparse input give the same input for descent paths.
591+
"""
592+
X, y, _, _ = build_dataset(n_samples=50, n_features=20)
593+
csr = sparse.csr_matrix(X)
594+
for path in [enet_path, lasso_path]:
595+
_, coefs, _ = path(X, y, fit_intercept=False)
596+
_, sparse_coefs, _ = path(csr, y, fit_intercept=False)
597+
assert_array_almost_equal(coefs, sparse_coefs)
598+
599+
588600
if __name__ == '__main__':
589601
import nose
590602
nose.runmodule()

0 commit comments

Comments
 (0)