@@ -496,6 +496,16 @@ def enet_path(
496
496
:ref:`examples/linear_model/plot_lasso_coordinate_descent_path.py
497
497
<sphx_glr_auto_examples_linear_model_plot_lasso_coordinate_descent_path.py>`.
498
498
"""
499
+ X_offset_param = params .pop ("X_offset" , None )
500
+ X_scale_param = params .pop ("X_scale" , None )
501
+ tol = params .pop ("tol" , 1e-4 )
502
+ max_iter = params .pop ("max_iter" , 1000 )
503
+ random_state = params .pop ("random_state" , None )
504
+ selection = params .pop ("selection" , "cyclic" )
505
+
506
+ if len (params ) > 0 :
507
+ raise ValueError ("Unexpected parameters in params" , params .keys ())
508
+
499
509
# We expect X and y to be already Fortran ordered when bypassing
500
510
# checks
501
511
if check_input :
@@ -532,10 +542,10 @@ def enet_path(
532
542
533
543
# MultiTaskElasticNet does not support sparse matrices
534
544
if not multi_output and sparse .isspmatrix (X ):
535
- if "X_offset" in params :
545
+ if X_offset_param is not None :
536
546
# As sparse matrices are not actually centered we need this
537
547
# to be passed to the CD solver.
538
- X_sparse_scaling = params [ "X_offset" ] / params [ "X_scale" ]
548
+ X_sparse_scaling = X_offset_param / X_scale_param
539
549
X_sparse_scaling = np .asarray (X_sparse_scaling , dtype = X .dtype )
540
550
else :
541
551
X_sparse_scaling = np .zeros (n_features , dtype = X .dtype )
@@ -571,13 +581,10 @@ def enet_path(
571
581
alphas = np .sort (alphas )[::- 1 ] # make sure alphas are properly ordered
572
582
573
583
n_alphas = len (alphas )
574
- tol = params .get ("tol" , 1e-4 )
575
- max_iter = params .get ("max_iter" , 1000 )
576
584
dual_gaps = np .empty (n_alphas )
577
585
n_iters = []
578
586
579
- rng = check_random_state (params .get ("random_state" , None ))
580
- selection = params .get ("selection" , "cyclic" )
587
+ rng = check_random_state (random_state )
581
588
if selection not in ["random" , "cyclic" ]:
582
589
raise ValueError ("selection should be either random or cyclic." )
583
590
random = selection == "random"
@@ -1016,7 +1023,6 @@ def fit(self, X, y, sample_weight=None, check_input=True):
1016
1023
dual_gaps_ = np .zeros (n_targets , dtype = X .dtype )
1017
1024
self .n_iter_ = []
1018
1025
1019
- # FIXME: 'normalize' to be removed in 1.2
1020
1026
for k in range (n_targets ):
1021
1027
if Xy is not None :
1022
1028
this_Xy = Xy [:, k ]
@@ -1031,8 +1037,6 @@ def fit(self, X, y, sample_weight=None, check_input=True):
1031
1037
alphas = [alpha ],
1032
1038
precompute = precompute ,
1033
1039
Xy = this_Xy ,
1034
- fit_intercept = False ,
1035
- normalize = False ,
1036
1040
copy_X = True ,
1037
1041
verbose = False ,
1038
1042
tol = self .tol ,
@@ -1267,6 +1271,8 @@ def _path_residuals(
1267
1271
sample_weight ,
1268
1272
train ,
1269
1273
test ,
1274
+ normalize ,
1275
+ fit_intercept ,
1270
1276
path ,
1271
1277
path_params ,
1272
1278
alphas = None ,
@@ -1348,9 +1354,6 @@ def _path_residuals(
1348
1354
# for read-only memmaps (cf. numpy#14132).
1349
1355
array .setflags (write = True )
1350
1356
1351
- fit_intercept = path_params ["fit_intercept" ]
1352
- normalize = path_params ["normalize" ]
1353
-
1354
1357
if y .ndim == 1 :
1355
1358
precompute = path_params ["precompute" ]
1356
1359
else :
@@ -1577,7 +1580,11 @@ def fit(self, X, y, sample_weight=None):
1577
1580
path_params = self .get_params ()
1578
1581
1579
1582
# FIXME: 'normalize' to be removed in 1.2
1580
- path_params ["normalize" ] = _normalize
1583
+ # path_params["normalize"] = _normalize
1584
+ # Pop `intercept` and `normalize` that are not parameter of the path
1585
+ # function
1586
+ path_params .pop ("normalize" , None )
1587
+ path_params .pop ("fit_intercept" , None )
1581
1588
1582
1589
if "l1_ratio" in path_params :
1583
1590
l1_ratios = np .atleast_1d (path_params ["l1_ratio" ])
@@ -1635,6 +1642,8 @@ def fit(self, X, y, sample_weight=None):
1635
1642
sample_weight ,
1636
1643
train ,
1637
1644
test ,
1645
+ _normalize ,
1646
+ self .fit_intercept ,
1638
1647
self .path ,
1639
1648
path_params ,
1640
1649
alphas = this_alphas ,
0 commit comments