#NEWLINE# @ ignore_warnings #NEWLINE# def test_sag_classifier_computed_correctly( ) : #NEWLINE# #INDENT# 'tests if the binary classifier is computed correctly' #NEWLINE# alpha = 0.1 #NEWLINE# n_samples = 50 #NEWLINE# n_iter = 50 #NEWLINE# tol = 1e-05 #NEWLINE# fit_intercept = True #NEWLINE# ( X , y ) = make_blobs ( n_samples = n_samples , centers = 2 , random_state = 0 , cluster_std = 0.1 ) #NEWLINE# step_size = get_step_size ( X , alpha , fit_intercept , classification = True ) #NEWLINE# classes = np . unique ( y ) #NEWLINE# y_tmp = np . ones ( n_samples ) #NEWLINE# y_tmp [ ( y != classes [ 1 ] ) ] = ( - 1 ) #NEWLINE# y = y_tmp #NEWLINE# clf1 = LogisticRegression ( solver = 'sag' , C = ( ( 1.0 / alpha ) / n_samples ) , max_iter = n_iter , tol = tol , random_state = 77 , fit_intercept = fit_intercept ) #NEWLINE# clf2 = clone ( clf1 ) #NEWLINE# clf1 . fit ( X , y ) #NEWLINE# clf2 . fit ( sp . csr_matrix ( X ) , y ) #NEWLINE# ( spweights , spintercept ) = sag_sparse ( X , y , step_size , alpha , n_iter = n_iter , dloss = log_dloss , fit_intercept = fit_intercept ) #NEWLINE# ( spweights2 , spintercept2 ) = sag_sparse ( X , y , step_size , alpha , n_iter = n_iter , dloss = log_dloss , sparse = True , fit_intercept = fit_intercept ) #NEWLINE# assert_array_almost_equal ( clf1 . coef_ . ravel ( ) , spweights . ravel ( ) , decimal = 2 ) #NEWLINE# assert_almost_equal ( clf1 . intercept_ , spintercept , decimal = 1 ) #NEWLINE# assert_array_almost_equal ( clf2 . coef_ . ravel ( ) , spweights2 . ravel ( ) , decimal = 2 ) #NEWLINE# assert_almost_equal ( clf2 . intercept_ , spintercept2 , decimal = 1 )