Search code examples
pythonscikit-learnstatisticspcacovariance

Determine variance contribution of each player in python


after looking at a multitude of methods and posts, it is not yet clear to me how to solve this issue which seems intuitively simple. I have the following dataset with the scores of 5 players. Its sample variance is 2.98108.

PLAYER  |   SCORE
-------------------
Bernard |   22.66
Bernard |   27.365
Bernard |   22.814
Anton   |   25.012
Anton   |   23.676
Anton   |   23.954
Carine  |   24.722
Carine  |   24.026
Carine  |   24.335
Carine  |   24.05
Bernard |   23.925
Bernard |   24.355
Bernard |   26.699
Carine  |   27.999
David   |   28.701
David   |   22.57
David   |   22.365
David   |   25.49
David   |   26.757
David   |   23.878
David   |   24.609
David   |   22.803
Anton   |   25.227
Anton   |   25.348
Carine  |   27.523
Carine  |   28.38
Carine  |   28.628
Bernard |   26.651
Bernard |   25.377
Anton   |   27.767
Anton   |   24.81
Anton   |   24.835
Eloy    |   26.672
Eloy    |   25.683
Eloy    |   26.657
Eloy    |   24.463
Eloy    |   25.808
Eloy    |   25.414
Eloy    |   26.044
Eloy    |   25.619

I would like to determine to which extend each of the players contributed to the variance of the whole.

Anton   |   Bernard |   Carine  |   David   |   Eloy
------------------------------------------------------                              
25.227  |   26.651  |   24.722  |   28.701  |   26.672
25.348  |   25.377  |   24.026  |   22.57   |   25.683
27.767  |   22.66   |   24.335  |   22.365  |   26.657
24.81   |   27.365  |   24.05   |   25.49   |   24.463
24.835  |   22.814  |   27.523  |   26.757  |   25.808
25.012  |   23.925  |   28.38   |   23.878  |   25.414
23.676  |   24.355  |   28.628  |   24.609  |   26.044
23.954  |   26.699  |   27.999  |   22.803  |   25.619

Note that I do not have any target variable: I am not fitting the players scores to a dependant variable. This makes it (to me) difficult to use methods like the shapley value, sklearn.feature_selection.chi2, or feature_importances_ where fit and fit_transform require a target variable.

Scikit’s PCA gives the following matrices:

components_:

-0.21261656 |   0.56000412  |   -0.19875582 |   0.77420244  |   -0.04791964
-0.31918083 |   -0.29286871 |   0.83464075  |   0.33964441  |   0.01918345
0.50226936  |   -0.55051268 |   -0.21507693 |   0.50440938  |   0.37943954
0.08884174  |   -0.33440461 |   -0.13381735 |   0.17548621  |   -0.9119091
0.76990287  |   0.4309671   |   0.44688451  |   0.00529465  |   -0.14759107

explained_variance_ratio_:

0.43725481  |   0.38896865  |   0.14361466  |   0.01989021  |   0.01027166

I would like to have a result table like:

Anton       |   Bernard     |   Carine     |    David       |   Eloy
-------------------------------------------------------------------------                           
0.20195141  |   0.18162131  |   0.30601668  |   0.15273025  |   0.15768035

telling me that Carine was the biggest contributor with 30% of the total variance and so on for the remaining players.

Can I use those matrices (components and explained_variance_ratio) to infer the total contribution of each player to the total variance? If yes, how can I do it?

Thanks


Solution

  • Since each player has exactly 8 samples of data, sum the square errors from the (overall) mean for all the samples and sum these errors first by player (8 samples each, achieving 5 numbers) and sum these 5 numbers for an overall sum. Every of the 5 numbers, divided by this total, will give you the desired value.