understanding experimental data coefficient of determination when we fit curve to set of datawe are finding function that relates an independent variable (inches horizontally from the launch point in this exampleto predicted value of dependent variable (inches above the launch point in this exampleasking about the goodness of fit is equivalent to asking about the accuracy of these predictions recall that the fits were found by minimizing the mean square error this suggests that one could evaluate the goodness of fit by looking at the mean square error the problem with that approach is that while there is lower bound for the mean square error (zero)there is no upper bound this means that while the mean square error is useful for comparing the relative goodness of two fits to the same datait is not particularly useful for getting sense of the absolute goodness of fit we can calculate the absolute goodness of fit using the coefficient of determinationoften written as let !be the !observed value!be the corresponding value predicted by modeland be the mean of the observed values ! (!!(!!by comparing the estimation errors (the numeratorwith the variability of the original values (the denominator) is intended to capture the proportion of variability in data set that is accounted for by the statistical model provided by the fit when the model being evaluated is produced by linear regressionthe value of always lies between and if the model explains all of the variability in the data if there is no relationship between the values predicted by the model and the actual data the code in figure provides straightforward implementation of this statistical measure its compactness stems from the expressiveness of the operations on arrays the expression (predicted measured)** subtracts the elements of one array from the elements of anotherand then squares each element in the result the expression (measured meanofmeasured)** subtracts the scalar value meanofmeasured from each element of the array measuredand then squares each element of the results def rsquared(measuredpredicted)"""assumes measured one-dimensional array of measured values predicted one-dimensional array of predicted values returns coefficient of determination""estimateerror ((predicted measured)** sum(meanofmeasured measured sum()/float(len(measured)variability ((measured meanofmeasured)** sum(return estimateerror/variability figure computing there are several different definitions of the coefficient of determination the definition supplied here is used to evaluate the quality of fit produced by linear regression