uy generate_data (beta sig ntraining data np ones (( )for in p_range if np hstack ((xu**( - ))betahat [psolve ( xx yu_test y_test generate_data (beta sig #test data mse [x_test np ones (( )for in p_range if x_test np hstack (x_test u_test **( - ))y_hat x_test betahat [ppredictions mse append (np sum (y_test y_hat )** / )totmse totmse np array (mseplt plot(p_range mse ,' ',alpha = plt plot(p_range totmse / ,' - 'plt xticks ticks p_range plt xlabel ('number of parameters $ 'plt ylabel ('test loss 'plt tight_layout (plt savefig ('mserepeatpy pdf ',format ='pdf 'plt show ( bootstrapping bootstrap method the bootstrap method [ combines cmc estimation with the resampling procedure of section the idea is as followssuppose we wish to estimate number via some estimator ( )where :{ xn is an iid sample from some unknown cdf it is assumed that does not depend on the order of the {xi to assess the quality (for exampleaccuracyof the estimator yone could draw independent replications tn of and find sample estimates for quantities such as the variance varythe bias ey uand the mean squared error ( ) howeverit may be too time-consuming or simply not feasible to obtain such replications an alternative is to resample the original data to reiterategiven an outcome { xn of we simulate an iid sample :{ xnfrom the empirical cdf fn via algorithm (hence the resampling size is herethe rationale is that the empirical cdf fn is close to the actual cdf and gets closer as gets larger henceany quantities depending on fsuch as ef ( )where is functioncan be approximated by efn (ythe latter is usually still difficult to evaluatebut it can be simply estimated via cmc as (yi) = where ykare independent random variableseach distributed as ( this seemingly self-referent procedure is called bootstrapping -alluding to baron von mun