def validation_error(selflearnererror_measure**other_params)error tryfor in range(self num_folds)predictor learner(selftrain=list(self fold_complement( ))**other_paramslearn(error +sumerror_measure(predictor( )self target( )for in self fold( )except valueerrorreturn float("inf"#infinity return error/len(self datathe plot error method plots the average error as function of the minimum number of examples in decision-tree searchboth for the validation set and for the test set the error on the validation set can be used to tune the parameter -choose the value of the parameter that minimizes the error the error on the test set cannot be used to tune the parametersif is were to be used this way then it cannot be used to test learncrossvalidation py -(continued def plot_error(datacriterion=evaluate squared_lossleaf_prediction=predict empiricalnum_folds= maxx=nonexscale='linear')"""plots the error on the validation set and the test set with respect to settings of the minimum number of examples xscale should be 'logor 'linear""plt ion(plt xscale(xscalechange between log and linear scale plt xlabel("min_child_weight"plt ylabel("average "+criterion __doc__folded_data k_fold_dataset(datanum_foldsif maxx =nonemaxx len(data train)// + verrors [validation errors terrors [test set errors for mcw in range( ,maxx)verrors append(folded_data validation_error(dt_learner,criterion,leaf_prediction=leaf_predi min_child_weight=mcw)tree dt_learner(datacriterionleaf_prediction=leaf_predictionmin_child_weight=mcwlearn(terrors append(data evaluate_dataset(data test,tree,criterion)plt plot(range( ,maxx)verrorsls='-',color=' 'label="validation for "+criterion __doc__plt plot(range( ,maxx)terrorsls='--',color=' 'label="test set for "+criterion __doc__plt legend(plt draw( the following produces figure of poole and mackworth [ version june