<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from sklearn . datasets import load_boston <EOL> from sklearn . ensemble import RandomForestRegressor <EOL> from sklearn . pipeline import Pipeline <EOL> from sklearn . preprocessing import Imputer <EOL> from sklearn . model_selection import cross_val_score <EOL> rng = np . random . RandomState ( <NUM_LIT:0> ) <EOL> dataset = load_boston ( ) <EOL> X_full , y_full = dataset . data , dataset . target <EOL> n_samples = X_full . shape [ <NUM_LIT:0> ] <EOL> n_features = X_full . shape [ <NUM_LIT:1> ] <EOL> estimator = RandomForestRegressor ( random_state = <NUM_LIT:0> , n_estimators = <NUM_LIT:100> ) <EOL> score = cross_val_score ( estimator , X_full , y_full ) . mean ( ) <EOL> print ( "<STR_LIT>" % score ) <EOL> missing_rate = <NUM_LIT> <EOL> n_missing_samples = int ( n_samples * missing_rate ) <EOL> missing_samples = np . hstack ( ( np . zeros ( n_samples - n_missing_samples , <EOL> dtype = np . bool ) , <EOL> np . ones ( n_missing_samples , <EOL> dtype = np . bool ) ) ) <EOL> rng . shuffle ( missing_samples ) <EOL> missing_features = rng . randint ( <NUM_LIT:0> , n_features , n_missing_samples ) <EOL> X_filtered = X_full [ ~ missing_samples , : ] <EOL> y_filtered = y_full [ ~ missing_samples ] <EOL> estimator = RandomForestRegressor ( random_state = <NUM_LIT:0> , n_estimators = <NUM_LIT:100> ) <EOL> score = cross_val_score ( estimator , X_filtered , y_filtered ) . mean ( ) <EOL> print ( "<STR_LIT>" % score ) <EOL> X_missing = X_full . copy ( ) <EOL> X_missing [ np . where ( missing_samples ) [ <NUM_LIT:0> ] , missing_features ] = <NUM_LIT:0> <EOL> y_missing = y_full . copy ( ) <EOL> estimator = Pipeline ( [ ( "<STR_LIT>" , Imputer ( missing_values = <NUM_LIT:0> , <EOL> strategy = "<STR_LIT>" , <EOL> axis = <NUM_LIT:0> ) ) , <EOL> ( "<STR_LIT>" , RandomForestRegressor ( random_state = <NUM_LIT:0> , <EOL> n_estimators = <NUM_LIT:100> ) ) ] ) <EOL> score = cross_val_score ( estimator , X_missing , y_missing ) . mean ( ) <EOL> print ( "<STR_LIT>" % score ) <EOL> estimator = Pipeline ( [ ( "<STR_LIT>" , Imputer ( missing_values = <NUM_LIT:0> , <EOL> strategy = "<STR_LIT>" , <EOL> axis = <NUM_LIT:0> , add_indicator_features = True ) ) , <EOL> ( "<STR_LIT>" , RandomForestRegressor ( random_state = <NUM_LIT:0> , <EOL> n_estimators = <NUM_LIT:100> ) ) ] ) <EOL> score = cross_val_score ( estimator , X_missing , y_missing ) . mean ( ) <EOL> print ( "<STR_LIT>" % score ) </s>
