<s> """<STR_LIT>""" <EOL> print ( __doc__ ) <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from sklearn import datasets <EOL> from sklearn . tree import DecisionTreeClassifier <EOL> from sklearn . metrics import zero_one_loss <EOL> from sklearn . ensemble import AdaBoostClassifier <EOL> n_estimators = <NUM_LIT> <EOL> learning_rate = <NUM_LIT:1.> <EOL> X , y = datasets . make_hastie_10_2 ( n_samples = <NUM_LIT> , random_state = <NUM_LIT:1> ) <EOL> X_test , y_test = X [ <NUM_LIT> : ] , y [ <NUM_LIT> : ] <EOL> X_train , y_train = X [ : <NUM_LIT> ] , y [ : <NUM_LIT> ] <EOL> dt_stump = DecisionTreeClassifier ( max_depth = <NUM_LIT:1> , min_samples_leaf = <NUM_LIT:1> ) <EOL> dt_stump . fit ( X_train , y_train ) <EOL> dt_stump_err = <NUM_LIT:1.0> - dt_stump . score ( X_test , y_test ) <EOL> dt = DecisionTreeClassifier ( max_depth = <NUM_LIT:9> , min_samples_leaf = <NUM_LIT:1> ) <EOL> dt . fit ( X_train , y_train ) <EOL> dt_err = <NUM_LIT:1.0> - dt . score ( X_test , y_test ) <EOL> ada_discrete = AdaBoostClassifier ( <EOL> base_estimator = dt_stump , <EOL> learning_rate = learning_rate , <EOL> n_estimators = n_estimators , <EOL> algorithm = "<STR_LIT>" ) <EOL> ada_discrete . fit ( X_train , y_train ) <EOL> ada_real = AdaBoostClassifier ( <EOL> base_estimator = dt_stump , <EOL> learning_rate = learning_rate , <EOL> n_estimators = n_estimators , <EOL> algorithm = "<STR_LIT>" ) <EOL> ada_real . fit ( X_train , y_train ) <EOL> fig = plt . figure ( ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> ax . plot ( [ <NUM_LIT:1> , n_estimators ] , [ dt_stump_err ] * <NUM_LIT:2> , '<STR_LIT>' , <EOL> label = '<STR_LIT>' ) <EOL> ax . plot ( [ <NUM_LIT:1> , n_estimators ] , [ dt_err ] * <NUM_LIT:2> , '<STR_LIT>' , <EOL> label = '<STR_LIT>' ) <EOL> ada_discrete_err = np . zeros ( ( n_estimators , ) ) <EOL> for i , y_pred in enumerate ( ada_discrete . staged_predict ( X_test ) ) : <EOL> ada_discrete_err [ i ] = zero_one_loss ( y_pred , y_test ) <EOL> ada_discrete_err_train = np . zeros ( ( n_estimators , ) ) <EOL> for i , y_pred in enumerate ( ada_discrete . staged_predict ( X_train ) ) : <EOL> ada_discrete_err_train [ i ] = zero_one_loss ( y_pred , y_train ) <EOL> ada_real_err = np . zeros ( ( n_estimators , ) ) <EOL> for i , y_pred in enumerate ( ada_real . staged_predict ( X_test ) ) : <EOL> ada_real_err [ i ] = zero_one_loss ( y_pred , y_test ) <EOL> ada_real_err_train = np . zeros ( ( n_estimators , ) ) <EOL> for i , y_pred in enumerate ( ada_real . staged_predict ( X_train ) ) : <EOL> ada_real_err_train [ i ] = zero_one_loss ( y_pred , y_train ) <EOL> ax . plot ( np . arange ( n_estimators ) + <NUM_LIT:1> , ada_discrete_err , <EOL> label = '<STR_LIT>' , <EOL> color = '<STR_LIT>' ) <EOL> ax . plot ( np . arange ( n_estimators ) + <NUM_LIT:1> , ada_discrete_err_train , <EOL> label = '<STR_LIT>' , <EOL> color = '<STR_LIT>' ) <EOL> ax . plot ( np . arange ( n_estimators ) + <NUM_LIT:1> , ada_real_err , <EOL> label = '<STR_LIT>' , <EOL> color = '<STR_LIT>' ) <EOL> ax . plot ( np . arange ( n_estimators ) + <NUM_LIT:1> , ada_real_err_train , <EOL> label = '<STR_LIT>' , <EOL> color = '<STR_LIT>' ) <EOL> ax . set_ylim ( ( <NUM_LIT:0.0> , <NUM_LIT:0.5> ) ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> leg = ax . legend ( loc = '<STR_LIT>' , fancybox = True ) <EOL> leg . get_frame ( ) . set_alpha ( <NUM_LIT> ) <EOL> plt . show ( ) </s>
