#NEWLINE# def feature_selection( feat_select , X , y ) : #NEWLINE# #INDENT# '" Implements various kinds of feature selection ' #NEWLINE# if ( re . match ( '.*-best' , feat_select ) is not None ) : #NEWLINE# #INDENT# n = int ( feat_select . split ( '-' ) [ 0 ] ) #NEWLINE# selector = SelectKBest ( k = n ) #NEWLINE# import warnings #NEWLINE# with warnings . catch_warnings ( ) : #NEWLINE# #INDENT# warnings . simplefilter ( 'ignore' , category = UserWarning ) #NEWLINE# features_selected = np . where ( ( selector . fit ( X , y ) . get_support ( ) == True ) ) [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( re . match ( '.*-randombest' , feat_select ) is not None ) : #NEWLINE# #INDENT# n = int ( feat_select . split ( '-' ) [ 0 ] ) #NEWLINE# from random import shuffle #NEWLINE# features = range ( 0 , y . shape [ 1 ] ) #NEWLINE# shuffle ( features ) #NEWLINE# features_selected = features [ : n ] #NEWLINE# #UNINDENT# #UNINDENT# return features_selected