#NEWLINE# def test_iforest_sparse( ) : #NEWLINE# #INDENT# 'Check IForest for various parameter settings on sparse input.' #NEWLINE# rng = check_random_state ( 0 ) #NEWLINE# ( X_train , X_test , y_train , y_test ) = train_test_split ( boston . data [ : 50 ] , boston . target [ : 50 ] , random_state = rng ) #NEWLINE# grid = ParameterGrid ( { #NEWLINE# #INDENT# 'max_samples' : [ 0.5 , 1.0 ] , #NEWLINE# 'bootstrap' : [ True , False ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# for sparse_format in [ csc_matrix , csr_matrix ] : #NEWLINE# #INDENT# X_train_sparse = sparse_format ( X_train ) #NEWLINE# X_test_sparse = sparse_format ( X_test ) #NEWLINE# for params in grid : #NEWLINE# #INDENT# sparse_classifier = IsolationForest ( n_estimators = 10 , random_state = 1 , ** params ) . fit ( X_train_sparse ) #NEWLINE# sparse_results = sparse_classifier . predict ( X_test_sparse ) #NEWLINE# dense_classifier = IsolationForest ( n_estimators = 10 , random_state = 1 , ** params ) . fit ( X_train ) #NEWLINE# dense_results = dense_classifier . predict ( X_test ) #NEWLINE# assert_array_equal ( sparse_results , dense_results ) #NEWLINE# assert_array_equal ( sparse_results , dense_results )