A C# implementation of coefficient of determination.
From Wikipedia:
"In statistics, the coefficient of determination R2 is used in the context of statistical models whose main purpose is the prediction of future outcomes on the basis of other related information. It is the proportion of variability in a data set that is accounted for by the statistical model Steel and Torrie, 1960. It provides a measure of how well future outcomes are likely to be predicted by the model. There are several different definitions of R2 which are only sometimes equivalent. One class of such cases includes that of linear regression. In this case, if an intercept is included then R2 is simply the square of the sample correlation coefficient between the outcomes and their predicted values, or in the case of simple linear regression, between the outcomes and the values of the single regressor being used for prediction. In such cases, the coefficient of determination ranges from 0 to 1. Important cases where the computational definition of R2 can yield negative values, depending on the definition used, arise where the predictions which are being compared to the corresponding outcomes have not been derived from a model-fitting procedure using those data, and where linear regression is conducted without including an intercept."
Steel, R. G. D. and Torrie, J. H., Principles and Procedures of Statistics, New York: McGraw-Hill, 1960, pp. 187, 287.