#NEWLINE# @ ignore_warnings #NEWLINE# def test_sag_regressor( ) : #NEWLINE# #INDENT# 'tests if the sag regressor performs well' #NEWLINE# ( xmin , xmax ) = ( ( - 5 ) , 5 ) #NEWLINE# n_samples = 20 #NEWLINE# tol = 0.001 #NEWLINE# max_iter = 20 #NEWLINE# alpha = 0.1 #NEWLINE# rng = np . random . RandomState ( 0 ) #NEWLINE# X = np . linspace ( xmin , xmax , n_samples ) . reshape ( n_samples , 1 ) #NEWLINE# y = ( 0.5 * X . ravel ( ) ) #NEWLINE# clf1 = Ridge ( tol = tol , solver = 'sag' , max_iter = max_iter , alpha = ( alpha * n_samples ) ) #NEWLINE# clf2 = clone ( clf1 ) #NEWLINE# clf1 . fit ( X , n_samples ) #NEWLINE# clf2 . fit ( sp . csr_matrix ( X ) , y ) #NEWLINE# score1 = clf1 . score ( X , y ) #NEWLINE# score2 = clf2 . score ( X , y ) #NEWLINE# assert_greater ( score1 , 0.99 ) #NEWLINE# assert_greater ( score2 , 0.99 ) #NEWLINE# y = ( ( 0.5 * X . ravel ( ) ) + rng . randn ( n_samples , 1 ) . ravel ( ) ) #NEWLINE# clf1 = Ridge ( tol = tol , solver = 'sag' , max_iter = max_iter , alpha = ( alpha * n_samples ) ) #NEWLINE# clf2 = clone ( clf1 ) #NEWLINE# clf1 . fit ( X , y ) #NEWLINE# clf2 . fit ( sp . csr_matrix ( X ) , y ) #NEWLINE# score1 = clf1 . score ( X , y ) #NEWLINE# score2 = clf2 . score ( X , y ) #NEWLINE# score2 = clf2 . score ( X , y ) #NEWLINE# assert_greater ( score1 , 0.5 ) #NEWLINE# assert_greater ( score2 , 0.5 )