8000 TST: Added a test as proof of concept. · scikit-learn/scikit-learn@bc94923 · GitHub
[go: up one dir, main page]

Skip to content

Commit bc94923

Browse files
committed
TST: Added a test as proof of concept.
Added a test to show that the number of passes made are smaller for stopping="objective" even on a small dataset.
1 parent 2bf2a8d commit bc94923

File tree

2 files changed

+26
-3
lines changed
Filter options

2 files changed

+26
-3
lines changed

sklearn/linear_model/coordinate_descent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,6 @@ def enet_path(X, y, l1_ratio=0.5, eps=1e-3, n_alphas=100, alphas=None,
492492
coef_ = np.asfortranarray(coef_init)
493493

494494
for i, alpha in enumerate(alphas):
495-
#print alpha
496495
l1_reg = alpha * l1_ratio * n_samples
497496
l2_reg = alpha * (1.0 - l1_ratio) * n_samples
498497
if not multi_output and sparse.isspmatrix(X):

sklearn/linear_model/tests/test_coordinate_descent.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from scipy import interpolate, sparse
99
from copy import deepcopy
1010

11-
from sklearn.datasets import load_boston
11+
from sklearn.datasets import load_boston, make_regression
1212
from sklearn.utils.testing import assert_array_almost_equal
1313
from sklearn.utils.testing import assert_almost_equal
1414
from sklearn.utils.testing import assert_equal
@@ -21,7 +21,7 @@
2121

2222
from sklearn.linear_model.coordinate_descent import Lasso, \
2323
LassoCV, ElasticNet, ElasticNetCV, MultiTaskLasso, MultiTaskElasticNet, \
24-
MultiTaskElasticNetCV, MultiTaskLassoCV, lasso_path
24+
MultiTaskElasticNetCV, MultiTaskLassoCV, lasso_path, enet_path
2525
from sklearn.linear_model import LassoLarsCV, lars_path
2626

2727

@@ -574,6 +574,30 @@ def test_deprection_precompute_enet():
574574
assert_warns(DeprecationWarning, clf.fit, X, y)
575575

576576

577+
def test_n_passes_stopping_criteria():
578+
"""Test the number of passes for the stopping condition.
579+
580+
Ideally, when stopping is set to 'objective' lesser number of passes
581+
should be made on the data.
582+
"""
583+
X, y = make_regression()
584+
models = enet_path(X, y, precompute=False, return_n_iter=True, tol=1e-7,
585+
stopping="objective")
586+
n_iters_obj = sum(models[-1])
587+
models = enet_path(X, y, precompute=False, return_n_iter=True, tol=1e-4,
588+
stopping="dual_gap")
589+
n_iters_dual = sum(models[-1])
590+
assert_greater(n_iters_dual, n_iters_obj)
591+
592+
models = lasso_path(X, y, precompute=False, return_n_iter=True, tol=1e-7,
593+
stopping="objective")
594+
n_iters_obj = sum(models[-1])
595+
models = lasso_path(X, y, precompute=False, return_n_iter=True, tol=1e-4,
596+
stopping="dual_gap")
597+
n_iters_dual = sum(models[-1])
598+
assert_greater(n_iters_dual, n_iters_obj)
599+
600+
577601
if __name__ == '__main__':
578602
import nose
579603
nose.runmodule()

0 commit comments

Comments
 (0)
0