1
$\begingroup$

I am using scikit-learn r2_score function and I would like to understand what the option 'variance_weighted' calculates. In the documentation page it tells: Scores of all outputs are averaged, weighted by the variances of each individual output. Does it mean that the output is a weighted average whose weights are the variances of data of which score has to be calculated ?

For example:

>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> r2_score(y_true, y_pred, multioutput='variance_weighted')

Here the variance for the first individual output means the variance of [0.5, 1, 0, 2] ?

Thanks in advance.

EDIT: the question has been answered from a computational point of view here in StackOverflow. So it calculates the r2 score between each element corresponding to each axis, so in this case between [0.5,-1,7] and [0,-1,8], [1,1,-6] and [2,2,-5] and the variances, that represent the weights I was looking for, are the variances corresponding to the true values and so the variance of [0.5,-1,7] and of [1,1,-6].

At this point my doubt is: why do they weigh the r2 scores results using the variance of true values ? In this way, a higher variance in true values would lead to a higher importance of the r2 score value computed between such true values and the corresponding predicted values...

$\endgroup$
3
  • $\begingroup$ Note that the utility of this function is debatable. $\endgroup$
    – Dave
    Dec 27, 2022 at 17:36
  • $\begingroup$ @Dave I do not find other scores in my case so I would like to understand how this works. $\endgroup$ Dec 28, 2022 at 10:52
  • $\begingroup$ This Data Science post of mine could be of interest. The post for not directly address $R^2$ but does consider loss function for multivariate regression modes and how to combine the predictions made for each marginal distribution. $\endgroup$
    – Dave
    Dec 28, 2022 at 14:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.