The R2 metric is implemented as the square of the pearson coefficient, this is only correct when evaluating a linear model.
When you have a non-linear model, the R2 metric will be different, and the one implemented will give incorrect results, which is what was happening to me when i used it.
The correct way of implementing the R2 metric without assuming a linear model is:
$$R^2(y, \hat{y}) = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}$$
where $y$ is the real data, $\hat{y}$ is the prediction and $\bar{y}$ is the mean of the samples.
The R2 metric is implemented as the square of the pearson coefficient, this is only correct when evaluating a linear model.
When you have a non-linear model, the R2 metric will be different, and the one implemented will give incorrect results, which is what was happening to me when i used it.
The correct way of implementing the R2 metric without assuming a linear model is: $$R^2(y, \hat{y}) = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}$$ where $y$ is the real data, $\hat{y}$ is the prediction and $\bar{y}$ is the mean of the samples.