<s> """<STR_LIT>""" <EOL> import os , sys <EOL> import numpy as np <EOL> import pylab as pl <EOL> from sklearn . tree import DecisionTreeRegressor <EOL> from sklearn import metrics <EOL> try : <EOL> datadir = sys . argv [ <NUM_LIT:1> ] <EOL> except : <EOL> print __doc__ <EOL> sys . exit ( ) <EOL> def compute_rms_error ( y_pred , y_true ) : <EOL> """<STR_LIT>""" <EOL> return np . sqrt ( metrics . mean_squared_error ( y_pred , y_true ) ) <EOL> def compute_outlier_fraction ( y_pred , y_true , cutoff = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> return np . sum ( ( abs ( y_pred - y_true ) > cutoff ) ) * <NUM_LIT:1.> / len ( y_pred ) <EOL> data = np . load ( os . path . join ( datadir , '<STR_LIT>' ) ) <EOL> data = data [ : <NUM_LIT> ] <EOL> print '<STR_LIT>' % data . shape [ <NUM_LIT:0> ] <EOL> u , g , r , i , z = [ data [ f ] for f in '<STR_LIT>' ] <EOL> X = np . zeros ( ( len ( data ) , <NUM_LIT:4> ) ) <EOL> X [ : , <NUM_LIT:0> ] = u - g <EOL> X [ : , <NUM_LIT:1> ] = g - r <EOL> X [ : , <NUM_LIT:2> ] = r - i <EOL> X [ : , <NUM_LIT:3> ] = i - z <EOL> y = data [ '<STR_LIT>' ] <EOL> Ntot = len ( y ) <EOL> Ncv = Ntot / <NUM_LIT:5> <EOL> Ntest = Ntot / <NUM_LIT:5> <EOL> Ntrain = Ntot - Ncv - Ntest <EOL> X_train = X [ : Ntrain ] <EOL> y_train = y [ : Ntrain ] <EOL> X_cv = X [ Ntrain : Ntrain + Ncv ] <EOL> y_cv = y [ Ntrain : Ntrain + Ncv ] <EOL> X_test = X [ Ntrain + Ncv : ] <EOL> y_test = y [ Ntrain + Ncv : ] <EOL> max_depth_array = [ ] <EOL> train_error = [ ] <EOL> cv_error = [ ] <EOL> pl . figure ( ) <EOL> pl . plot ( max_depth_array , cv_error , label = '<STR_LIT>' ) <EOL> pl . plot ( max_depth_array , train_error , label = '<STR_LIT>' ) <EOL> pl . legend ( ) <EOL> pl . xlabel ( '<STR_LIT>' ) <EOL> pl . ylabel ( '<STR_LIT:error>' ) <EOL> max_depth = max_depth_array [ np . argmin ( cv_error ) ] <EOL> print "<STR_LIT>" % max_depth <EOL> n_samples_array = [ ] <EOL> train_error = [ ] <EOL> cv_error = [ ] <EOL> pl . figure ( ) <EOL> pl . plot ( n_samples_array , cv_error , label = '<STR_LIT>' ) <EOL> pl . plot ( n_samples_array , train_error , label = '<STR_LIT>' ) <EOL> pl . legend ( ) <EOL> pl . xlabel ( '<STR_LIT>' ) <EOL> pl . ylabel ( '<STR_LIT:error>' ) <EOL> pl . show ( ) </s>
