21
21
from ..base import RegressorMixin , MultiOutputMixin
22
22
# mypy error: Module 'sklearn.utils' has no attribute 'arrayfuncs'
23
23
from ..utils import arrayfuncs , as_float_array # type: ignore
24
+ from ..utils import check_random_state
24
25
from ..model_selection import check_cv
25
26
from ..exceptions import ConvergenceWarning
26
27
@@ -800,6 +801,16 @@ class Lars(MultiOutputMixin, RegressorMixin, LinearModel):
800
801
setting ``fit_path`` to ``False`` will lead to a speedup, especially
801
802
with a small alpha.
802
803
804
+ jitter : float, default=None
805
+ Upper bound on a uniform noise parameter to be added to the
806
+ `y` values, to satisfy the model's assumption of
807
+ one-at-a-time computations. Might help with stability.
808
+
809
+ random_state : int, RandomState instance or None (default)
810
+ Determines random number generation for jittering. Pass an int
811
+ for reproducible output across multiple function calls.
812
+ See :term:`Glossary <random_state>`. Ignored if `jitter` is None.
813
+
803
814
Attributes
804
815
----------
805
816
alphas_ : array-like of shape (n_alphas + 1,) | list of n_targets such \
@@ -846,7 +857,8 @@ class Lars(MultiOutputMixin, RegressorMixin, LinearModel):
846
857
847
858
def __init__ (self , fit_intercept = True , verbose = False , normalize = True ,
848
859
precompute = 'auto' , n_nonzero_coefs = 500 ,
849
- eps = np .finfo (np .float ).eps , copy_X = True , fit_path = True ):
860
+ eps = np .finfo (np .float ).eps , copy_X = True , fit_path = True ,
861
+ jitter = None , random_state = None ):
850
862
self .fit_intercept = fit_intercept
851
863
self .verbose = verbose
852
864
self .normalize = normalize
@@ -855,6 +867,8 @@ def __init__(self, fit_intercept=True, verbose=False, normalize=True,
855
867
self .eps = eps
856
868
self .copy_X = copy_X
857
869
self .fit_path = fit_path
870
+ self .jitter = jitter
871
+ self .random_state = random_state
858
872
859
873
@staticmethod
860
874
def _get_gram (precompute , X , y ):
@@ -954,6 +968,12 @@ def fit(self, X, y, Xy=None):
954
968
else :
955
969
max_iter = self .max_iter
956
970
971
+ if self .jitter is not None :
972
+ rng = check_random_state (self .random_state )
973
+
974
+ noise = rng .uniform (high = self .jitter , size = len (y ))
975
+ y = y + noise
976
+
957
977
self ._fit (X , y , max_iter = max_iter , alpha = alpha , fit_path = self .fit_path ,
958
978
Xy = Xy )
959
979
@@ -1031,6 +1051,16 @@ class LassoLars(Lars):
1031
1051
algorithm are typically in congruence with the solution of the
1032
1052
coordinate descent Lasso estimator.
1033
1053
1054
+ jitter : float, default=None
1055
+ Upper bound on a uniform noise parameter to be added to the
1056
+ `y` values, to satisfy the model's assumption of
1057
+ one-at-a-time computations. Might help with stability.
1058
+
1059
+ random_state : int, RandomState instance or None (default)
1060
+ Determines random number generation for jittering. Pass an int
1061
+ for reproducible output across multiple function calls.
1062
+ See :term:`Glossary <random_state>`. Ignored if `jitter` is None.
1063
+
1034
1064
Attributes
1035
1065
----------
1036
1066
alphas_ : array-like of shape (n_alphas + 1,) | list of n_targets such \
@@ -1083,7 +1113,7 @@ class LassoLars(Lars):
1083
1113
def __init__ (self , alpha = 1.0 , fit_intercept = True , verbose = False ,
1084
1114
normalize = True , precompute = 'auto' , max_iter = 500 ,
1085
1115
eps = np .finfo (np .float ).eps , copy_X = True , fit_path = True ,
1086
- positive = False ):
1116
+ positive = False , jitter = None , random_state = None ):
1087
1117
self .alpha = alpha
1088
1118
self .fit_intercept = fit_intercept
1089
1119
self .max_iter = max_iter
@@ -1094,6 +1124,8 @@ def __init__(self, alpha=1.0, fit_intercept=True, verbose=False,
1094
1124
self .copy_X = copy_X
1095
1125
self .eps = eps
1096
1126
self .fit_path = fit_path
1127
+ self .jitter = jitter
1128
+ self .random_state = random_state
1097
1129
1098
1130
1099
1131
###############################################################################
0 commit comments