#NEWLINE# @ ignore_warnings #NEWLINE# def test_sag_multiclass_computed_correctly( ) : #NEWLINE# #INDENT# 'tests if the multiclass classifier is computed correctly' #NEWLINE# alpha = 0.1 #NEWLINE# n_samples = 20 #NEWLINE# tol = 1e-05 #NEWLINE# max_iter = 40 #NEWLINE# fit_intercept = True #NEWLINE# ( X , y ) = make_blobs ( n_samples = n_samples , centers = 3 , 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# clf1 = LogisticRegression ( solver = 'sag' , C = ( ( 1.0 / alpha ) / n_samples ) , max_iter = max_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# coef1 = [ ] #NEWLINE# intercept1 = [ ] #NEWLINE# coef2 = [ ] #NEWLINE# intercept2 = [ ] #NEWLINE# for cl in classes : #NEWLINE# #INDENT# y_encoded = np . ones ( n_samples ) #NEWLINE# y_encoded [ ( y != cl ) ] = ( - 1 ) #NEWLINE# ( spweights1 , spintercept1 ) = sag_sparse ( X , y_encoded , step_size , alpha , dloss = log_dloss , n_iter = max_iter , fit_intercept = fit_intercept ) #NEWLINE# ( spweights2 , spintercept2 ) = sag_sparse ( X , y_encoded , step_size , alpha , dloss = log_dloss , n_iter = max_iter , sparse = True , fit_intercept = fit_intercept ) #NEWLINE# coef1 . append ( spweights1 ) #NEWLINE# intercept1 . append ( spintercept1 ) #NEWLINE# coef2 . append ( spweights2 ) #NEWLINE# intercept2 . append ( spintercept2 ) #NEWLINE# #UNINDENT# coef1 = np . vstack ( coef1 ) #NEWLINE# intercept1 = np . array ( intercept1 ) #NEWLINE# coef2 = np . vstack ( coef2 ) #NEWLINE# intercept2 = np . array ( intercept2 ) #NEWLINE# for ( i , cl ) in enumerate ( classes ) : #NEWLINE# #INDENT# assert_array_almost_equal ( clf1 . coef_ [ i ] . ravel ( ) , coef1 [ i ] . ravel ( ) , decimal = 2 ) #NEWLINE# assert_almost_equal ( clf1 . intercept_ [ i ] , intercept1 [ i ] , decimal = 1 ) #NEWLINE# assert_array_almost_equal ( clf2 . coef_ [ i ] . ravel ( ) , coef2 [ i ] . ravel ( ) , decimal = 2 ) #NEWLINE# assert_almost_equal ( clf2 . intercept_ [ i ] , intercept2 [ i ] , decimal = 1 )