@@ -108,24 +108,25 @@ def test_ridge_singular():
108108
109109def test_ridge_sample_weights ():
110110 rng = np .random .RandomState (0 )
111- alpha = 1.0
112111
113- #for solver in ("svd", "sparse_cg", "dense_cholesky", "lsqr"):
114112 for solver in ("dense_cholesky" , ):
115113 for n_samples , n_features in ((6 , 5 ), (5 , 10 )):
116- y = rng .randn (n_samples )
117- X = rng .randn (n_samples , n_features )
118- sample_weight = 1 + rng .rand (n_samples )
119-
120- coefs = ridge_regression (X , y , alpha , sample_weight ,
121- solver = solver )
122- # Sample weight can be implemented via a simple rescaling
123- # for the square loss
124- coefs2 = ridge_regression (
125- X * np .sqrt (sample_weight )[:, np .newaxis ],
126- y * np .sqrt (sample_weight ),
127- alpha , solver = solver )
128- assert_array_almost_equal (coefs , coefs2 )
114+ for alpha in (1.0 , 1e-2 ):
115+ y = rng .randn (n_samples )
116+ X = rng .randn (n_samples , n_features )
117+ sample_weight = 1 + rng .rand (n_samples )
118+
119+ coefs = ridge_regression (X , y ,
120+ alpha = alpha ,
121+ sample_weight = sample_weight ,
122+ solver = solver )
123+ # Sample weight can be implemented via a simple rescaling
124+ # for the square loss.
125+ coefs2 = ridge_regression (
126+ X * np .sqrt (sample_weight )[:, np .newaxis ],
127+ y * np .sqrt (sample_weight ),
128+ alpha = alpha , solver = solver )
129+ assert_array_almost_equal (coefs , coefs2 )
129130
130131
131132def test_ridge_shapes ():
0 commit comments