#NEWLINE# def smote_bootstrap_sample( self , X , y , b , k ) : #NEWLINE# #INDENT# classes = np . unique ( y ) #NEWLINE# count = np . bincount ( y ) #NEWLINE# majority_class = count . argmax ( ) #NEWLINE# majority_count = count . max ( ) #NEWLINE# data = np . empty ( ( 0 , X . shape [ 1 ] ) ) #NEWLINE# target = np . empty ( ( 0 , ) ) #NEWLINE# for i in classes : #NEWLINE# #INDENT# class_data = X [ ( y == i ) , : ] #NEWLINE# if ( i == majority_class ) : #NEWLINE# #INDENT# idx = np . random . choice ( majority_count , ( majority_count , ) ) #NEWLINE# data = np . concatenate ( ( data , class_data [ idx , : ] ) ) #NEWLINE# target = np . concatenate ( ( target , ( i * np . ones ( ( majority_count , ) ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sample_rate = ( ( majority_count / class_data . shape [ 0 ] ) * ( b / 100 ) ) #NEWLINE# idx = np . random . choice ( class_data . shape [ 0 ] , ( int ( ( sample_rate * class_data . shape [ 0 ] ) ) , ) ) #NEWLINE# sampled_class_data = class_data [ idx , : ] #NEWLINE# N_smote = int ( ( np . ceil ( ( ( majority_count / sampled_class_data . shape [ 0 ] ) * ( ( 1 - ( b / 100 ) ) + 1e-07 ) ) ) * 100 ) ) #NEWLINE# synthetic = smote ( sampled_class_data , N = N_smote , k = self . k ) #NEWLINE# n_missing = ( majority_count - sampled_class_data . shape [ 0 ] ) #NEWLINE# idx = np . random . choice ( synthetic . shape [ 0 ] , ( n_missing , ) ) #NEWLINE# new_class_data = np . concatenate ( ( sampled_class_data , synthetic [ idx , : ] ) ) #NEWLINE# data = np . concatenate ( ( data , new_class_data ) ) #NEWLINE# target = np . concatenate ( ( target , ( i * np . ones ( ( new_class_data . shape [ 0 ] , ) ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# return ( data , target )