#NEWLINE# def test_enet_toy_explicit_sparse_input( ) : #NEWLINE# #INDENT# f = ignore_warnings #NEWLINE# X = sp . lil_matrix ( ( 3 , 1 ) ) #NEWLINE# X [ ( 0 , 0 ) ] = ( - 1 ) #NEWLINE# X [ ( 2 , 0 ) ] = 1 #NEWLINE# Y = [ ( - 1 ) , 0 , 1 ] #NEWLINE# T = sp . lil_matrix ( ( 3 , 1 ) ) #NEWLINE# T [ ( 0 , 0 ) ] = 2 #NEWLINE# T [ ( 1 , 0 ) ] = 3 #NEWLINE# T [ ( 2 , 0 ) ] = 4 #NEWLINE# clf = ElasticNet ( alpha = 0 , l1_ratio = 1.0 ) #NEWLINE# f ( clf . fit ) ( X , Y ) #NEWLINE# pred = clf . predict ( T ) #NEWLINE# assert_array_almost_equal ( clf . coef_ , [ 1 ] ) #NEWLINE# assert_array_almost_equal ( pred , [ 2 , 3 , 4 ] ) #NEWLINE# assert_almost_equal ( clf . dual_gap_ , 0 ) #NEWLINE# clf = ElasticNet ( alpha = 0.5 , l1_ratio = 0.3 , max_iter = 1000 ) #NEWLINE# clf . fit ( X , Y ) #NEWLINE# pred = clf . predict ( T ) #NEWLINE# assert_array_almost_equal ( clf . coef_ , [ 0.50819 ] , decimal = 3 ) #NEWLINE# assert_array_almost_equal ( pred , [ 1.0163 , 1.5245 , 2.0327 ] , decimal = 3 ) #NEWLINE# assert_almost_equal ( clf . dual_gap_ , 0 ) #NEWLINE# clf = ElasticNet ( alpha = 0.5 , l1_ratio = 0.5 ) #NEWLINE# clf . fit ( X , Y ) #NEWLINE# pred = clf . predict ( Y ) #NEWLINE# assert_array_almost_equal ( clf . coef_ , [ 0.45454 ] , 3 ) #NEWLINE# assert_array_almost_equal ( pred , [ 0.909 , 1.3636 , 1.8181 ] , 3 ) #NEWLINE# assert_almost_equal ( clf . dual_gap_ , 0 )