algorithm crude monte carlo for independent data inputsimulation algorithm for sample size nconfidence level outputpoint estimate and approximate ( aconfidence interval for ey iid simulate yn pn = yi pn = (yi yn- return and the interval ( monte carlo integration example (monte carlo integrationin monte carlo integrationsimulation is used to evaluate complicated integrals considerfor examplethe integral | -( + + )/ dx dx dx iid defining | | / ( ) / with ( )we can write ey using the following python programwith sample size of we obtained an estimate with an approximate confidence interval ( mcint py import numpy as np from numpy import pi ( pi**( / lambda xc*np sqrt(np abs(np sum( ,axis = )) ** np random randn ( , (xmy np mean(ysy np std(yre sy/my/np sqrt(nprint ('estimate {: }ci ({: ,{: }format my my *( - *re)my *( + *re))estimate ci ( , example (example (cont )we return to the bias-variance tradeoff in example figure gives estimates of the (squared-errorgeneralization risk ( as function of the number of parameters in the model but how accurate are these estimatesbecause we know in this case the exact model for the datawe can use monte carlo simulation to estimate the generalization risk (for fixed training setand the expected generalization risk (averaged over all training setsprecisely all we need to do is repeat the data generationfittingand validation steps many times and then take averages of the results the following python code repeats times simulate the training set of size fit models up to size