features to the data we expect the feature selection to be able to identify the features that are noninformative and remove themin[ ]from sklearn datasets import load_breast_cancer from sklearn feature_selection import selectpercentile from sklearn model_selection import train_test_split cancer load_breast_cancer(get deterministic random numbers rng np random randomstate( noise rng normal(size=(len(cancer data) )add noise features to the data the first features are from the datasetthe next are noise x_w_noise np hstack([cancer datanoise]x_trainx_testy_trainy_test train_test_splitx_w_noisecancer targetrandom_state= test_size use f_classif (the defaultand selectpercentile to select of features select selectpercentile(percentile= select fit(x_trainy_traintransform training set x_train_selected select transform(x_trainprint("x_train shape{}format(x_train shape)print("x_train_selected shape{}format(x_train_selected shape)out[ ]x_train shape( x_train_selected shape( as you can seethe number of features was reduced from to ( percent of the original number of featureswe can find out which features have been selected using the get_support methodwhich returns boolean mask of the selected features (visualized in figure - )in[ ]mask select get_support(print(maskvisualize the mask -black is truewhite is false plt matshow(mask reshape( - )cmap='gray_r'plt xlabel("sample index"out[ ]true true true true true true true true true true true true true true true true true true true false true false true false false true true true true true false false false true false true automatic feature selection