In [38]:
obs = pd.read_csv("obs_matrix_newer_dataset.csv")
obs = obs.drop(['map_Cursed Hollow', 'allied_char_Gall', 'opposing_char_Gall', 'opposing_char_Zeratul', 'allied_char_Zeratul'], axis=1)
In [39]:
obs.head()
Out[39]:
allied_avg_hero_level allied_avg_mrr allied_char_Abathur allied_char_Alarak allied_char_Alexstrasza allied_char_Ana allied_char_Anubarak allied_char_Artanis allied_char_Arthas allied_char_Auriel ... opposing_char_Uther opposing_char_Valeera opposing_char_Valla opposing_char_Varian opposing_char_Xul opposing_char_Yrel opposing_char_Zagara opposing_char_Zarya opposing_char_Zuljin outcome
0 13.0 1726.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0
1 14.6 1616.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1
2 14.4 2317.2 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 ... 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0
3 16.6 2068.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1
4 13.4 2303.4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0

5 rows × 165 columns

In [40]:
obs.shape
Out[40]:
(238194, 165)
In [41]:
from statsmodels.discrete.discrete_model import Logit
from statsmodels.tools import add_constant
In [43]:
def demean(s):
    return s - s.mean()


obs['allied_avg_mrr']        = demean(obs['allied_avg_mrr'])
obs['allied_avg_hero_level'] = demean(obs['allied_avg_hero_level'])
obs['opp_avg_hero_level']    = demean(obs['opp_avg_hero_level'])
obs['opp_avg_mrr']           = demean(obs['opp_avg_mrr'])


obs['allied_avg_mrr**2']          = obs['allied_avg_mrr']**2
obs['allied_avg_hero_level**2']   = obs['allied_avg_hero_level']**2
obs['opp_avg_hero_level**2']      = obs['opp_avg_hero_level']**2
obs['opp_avg_mrr**2']             = obs['opp_avg_mrr']**2
      

lg = Logit(obs['outcome'], add_constant(obs.drop('outcome', axis=1)))
In [44]:
results = lg.fit()
Optimization terminated successfully.
         Current function value: 0.668012
         Iterations 4
In [45]:
results.summary()
Out[45]:
Logit Regression Results
Dep. Variable: outcome No. Observations: 238194
Model: Logit Df Residuals: 238025
Method: MLE Df Model: 168
Date: Tue, 11 Sep 2018 Pseudo R-squ.: 0.03626
Time: 16:56:05 Log-Likelihood: -1.5912e+05
converged: True LL-Null: -1.6510e+05
LLR p-value: 0.000
coef std err z P>|z| [0.025 0.975]
const -5.004e-13 0.169 -2.97e-12 1.000 -0.331 0.331
allied_avg_hero_level 0.0526 0.002 30.211 0.000 0.049 0.056
allied_avg_mrr 0.0013 2.77e-05 48.231 0.000 0.001 0.001
allied_char_Abathur -0.1298 0.033 -3.958 0.000 -0.194 -0.066
allied_char_Alarak -0.0221 0.029 -0.752 0.452 -0.080 0.036
allied_char_Alexstrasza -0.0179 0.037 -0.477 0.633 -0.091 0.055
allied_char_Ana 0.1026 0.038 2.701 0.007 0.028 0.177
allied_char_Anubarak 0.0114 0.030 0.382 0.703 -0.047 0.070
allied_char_Artanis 0.0908 0.028 3.290 0.001 0.037 0.145
allied_char_Arthas -0.0320 0.030 -1.076 0.282 -0.090 0.026
allied_char_Auriel -0.0145 0.038 -0.379 0.705 -0.089 0.060
allied_char_Azmodan -0.0072 0.027 -0.269 0.788 -0.059 0.045
allied_char_Blaze -0.0923 0.030 -3.086 0.002 -0.151 -0.034
allied_char_Brightwing 0.0156 0.037 0.420 0.675 -0.057 0.089
allied_char_Cassia 0.2426 0.028 8.572 0.000 0.187 0.298
allied_char_Chen -0.1356 0.048 -2.848 0.004 -0.229 -0.042
allied_char_Cho 0.2554 0.064 3.972 0.000 0.129 0.381
allied_char_Chromie -0.1465 0.029 -4.997 0.000 -0.204 -0.089
allied_char_D.Va -0.0254 0.037 -0.678 0.498 -0.099 0.048
allied_char_Deckard 0.0341 0.037 0.933 0.351 -0.038 0.106
allied_char_Dehaka 0.0745 0.028 2.690 0.007 0.020 0.129
allied_char_Diablo -0.1135 0.027 -4.207 0.000 -0.166 -0.061
allied_char_E.T.C. -0.0825 0.029 -2.856 0.004 -0.139 -0.026
allied_char_Falstad -0.0256 0.028 -0.913 0.361 -0.081 0.029
allied_char_Fenix 0.2055 0.027 7.636 0.000 0.153 0.258
allied_char_Garrosh -0.1943 0.029 -6.635 0.000 -0.252 -0.137
allied_char_Gazlowe 0.0634 0.037 1.709 0.087 -0.009 0.136
allied_char_Genji -0.0493 0.027 -1.825 0.068 -0.102 0.004
allied_char_Greymane -0.0589 0.029 -2.057 0.040 -0.115 -0.003
allied_char_Guldan -0.0910 0.027 -3.363 0.001 -0.144 -0.038
allied_char_Hanzo -0.3126 0.028 -10.985 0.000 -0.368 -0.257
allied_char_Illidan -0.0249 0.035 -0.717 0.474 -0.093 0.043
allied_char_Jaina 0.0605 0.026 2.313 0.021 0.009 0.112
allied_char_Johanna -0.0529 0.028 -1.917 0.055 -0.107 0.001
allied_char_Junkrat -0.1786 0.031 -5.690 0.000 -0.240 -0.117
allied_char_Kaelthas -0.1015 0.026 -3.832 0.000 -0.153 -0.050
allied_char_KelThuzad 0.0832 0.031 2.721 0.007 0.023 0.143
allied_char_Kerrigan 0.1571 0.034 4.593 0.000 0.090 0.224
allied_char_Kharazim 0.0454 0.038 1.202 0.230 -0.029 0.119
allied_char_Leoric 0.1254 0.030 4.128 0.000 0.066 0.185
allied_char_Li Li 0.0545 0.036 1.532 0.126 -0.015 0.124
allied_char_Li-Ming -0.1840 0.026 -6.979 0.000 -0.236 -0.132
allied_char_Lt. Morales -0.0605 0.039 -1.540 0.124 -0.138 0.016
allied_char_Lunara 0.0221 0.030 0.741 0.459 -0.036 0.081
allied_char_Lúcio -0.0914 0.038 -2.426 0.015 -0.165 -0.018
allied_char_Maiev -0.0208 0.036 -0.583 0.560 -0.091 0.049
allied_char_Malfurion -0.0682 0.036 -1.900 0.057 -0.139 0.002
allied_char_Malthael 0.0655 0.033 2.015 0.044 0.002 0.129
allied_char_Medivh -0.1845 0.039 -4.690 0.000 -0.262 -0.107
allied_char_Muradin -0.0081 0.027 -0.302 0.763 -0.061 0.044
allied_char_Murky 0.1365 0.043 3.204 0.001 0.053 0.220
allied_char_Nazeebo 0.0181 0.027 0.678 0.498 -0.034 0.071
allied_char_Nova -0.0953 0.037 -2.586 0.010 -0.167 -0.023
allied_char_Probius 0.1713 0.062 2.752 0.006 0.049 0.293
allied_char_Ragnaros 0.0026 0.032 0.082 0.935 -0.060 0.066
allied_char_Raynor 0.3884 0.026 14.951 0.000 0.337 0.439
allied_char_Rehgar 0.0866 0.036 2.389 0.017 0.016 0.158
allied_char_Rexxar 0.0933 0.044 2.134 0.033 0.008 0.179
allied_char_Samuro 0.1838 0.039 4.726 0.000 0.108 0.260
allied_char_Sgt. Hammer 0.1132 0.037 3.092 0.002 0.041 0.185
allied_char_Sonya 0.0615 0.027 2.267 0.023 0.008 0.115
allied_char_Stitches -0.0741 0.028 -2.681 0.007 -0.128 -0.020
allied_char_Stukov -0.0402 0.037 -1.101 0.271 -0.112 0.031
allied_char_Sylvanas -0.0508 0.030 -1.667 0.096 -0.111 0.009
allied_char_Tassadar -0.3643 0.045 -8.132 0.000 -0.452 -0.277
allied_char_The Butcher 0.0559 0.033 1.684 0.092 -0.009 0.121
allied_char_The Lost Vikings 0.0413 0.064 0.642 0.521 -0.085 0.167
allied_char_Thrall 0.0489 0.027 1.805 0.071 -0.004 0.102
allied_char_Tracer -0.0342 0.031 -1.118 0.264 -0.094 0.026
allied_char_Tychus -0.0568 0.030 -1.877 0.061 -0.116 0.003
allied_char_Tyrael -0.0131 0.035 -0.369 0.712 -0.083 0.056
allied_char_Tyrande -0.0780 0.035 -2.220 0.026 -0.147 -0.009
allied_char_Uther -0.0353 0.038 -0.930 0.352 -0.110 0.039
allied_char_Valeera -0.1088 0.039 -2.760 0.006 -0.186 -0.032
allied_char_Valla -0.0462 0.028 -1.649 0.099 -0.101 0.009
allied_char_Varian 0.0215 0.026 0.821 0.412 -0.030 0.073
allied_char_Xul 0.0868 0.041 2.119 0.034 0.007 0.167
allied_char_Yrel 0.1498 0.028 5.360 0.000 0.095 0.205
allied_char_Zagara 0.1467 0.031 4.781 0.000 0.087 0.207
allied_char_Zarya -0.0007 0.034 -0.020 0.984 -0.068 0.067
allied_char_Zuljin 0.0294 0.030 0.984 0.325 -0.029 0.088
map_Braxis Holdout -9.53e-16 0.015 -6.53e-14 1.000 -0.029 0.029
map_Infernal Shrines 6.13e-16 0.014 4.39e-14 1.000 -0.027 0.027
map_Sky Temple 2.046e-15 0.013 1.52e-13 1.000 -0.026 0.026
map_Towers of Doom 1.782e-15 0.013 1.32e-13 1.000 -0.026 0.026
opp_avg_hero_level -0.0526 0.002 -30.211 0.000 -0.056 -0.049
opp_avg_mrr -0.0013 2.77e-05 -48.231 0.000 -0.001 -0.001
opposing_char_Abathur 0.1298 0.033 3.958 0.000 0.066 0.194
opposing_char_Alarak 0.0221 0.029 0.752 0.452 -0.036 0.080
opposing_char_Alexstrasza 0.0179 0.037 0.477 0.633 -0.055 0.091
opposing_char_Ana -0.1026 0.038 -2.701 0.007 -0.177 -0.028
opposing_char_Anubarak -0.0114 0.030 -0.382 0.703 -0.070 0.047
opposing_char_Artanis -0.0908 0.028 -3.290 0.001 -0.145 -0.037
opposing_char_Arthas 0.0320 0.030 1.076 0.282 -0.026 0.090
opposing_char_Auriel 0.0145 0.038 0.379 0.705 -0.060 0.089
opposing_char_Azmodan 0.0072 0.027 0.269 0.788 -0.045 0.059
opposing_char_Blaze 0.0923 0.030 3.086 0.002 0.034 0.151
opposing_char_Brightwing -0.0156 0.037 -0.420 0.675 -0.089 0.057
opposing_char_Cassia -0.2426 0.028 -8.572 0.000 -0.298 -0.187
opposing_char_Chen 0.1356 0.048 2.848 0.004 0.042 0.229
opposing_char_Cho -0.2554 0.064 -3.972 0.000 -0.381 -0.129
opposing_char_Chromie 0.1465 0.029 4.997 0.000 0.089 0.204
opposing_char_D.Va 0.0254 0.037 0.678 0.498 -0.048 0.099
opposing_char_Deckard -0.0341 0.037 -0.933 0.351 -0.106 0.038
opposing_char_Dehaka -0.0745 0.028 -2.690 0.007 -0.129 -0.020
opposing_char_Diablo 0.1135 0.027 4.207 0.000 0.061 0.166
opposing_char_E.T.C. 0.0825 0.029 2.856 0.004 0.026 0.139
opposing_char_Falstad 0.0256 0.028 0.913 0.361 -0.029 0.081
opposing_char_Fenix -0.2055 0.027 -7.636 0.000 -0.258 -0.153
opposing_char_Garrosh 0.1943 0.029 6.635 0.000 0.137 0.252
opposing_char_Gazlowe -0.0634 0.037 -1.709 0.087 -0.136 0.009
opposing_char_Genji 0.0493 0.027 1.825 0.068 -0.004 0.102
opposing_char_Greymane 0.0589 0.029 2.057 0.040 0.003 0.115
opposing_char_Guldan 0.0910 0.027 3.363 0.001 0.038 0.144
opposing_char_Hanzo 0.3126 0.028 10.985 0.000 0.257 0.368
opposing_char_Illidan 0.0249 0.035 0.717 0.474 -0.043 0.093
opposing_char_Jaina -0.0605 0.026 -2.313 0.021 -0.112 -0.009
opposing_char_Johanna 0.0529 0.028 1.917 0.055 -0.001 0.107
opposing_char_Junkrat 0.1786 0.031 5.690 0.000 0.117 0.240
opposing_char_Kaelthas 0.1015 0.026 3.832 0.000 0.050 0.153
opposing_char_KelThuzad -0.0832 0.031 -2.721 0.007 -0.143 -0.023
opposing_char_Kerrigan -0.1571 0.034 -4.593 0.000 -0.224 -0.090
opposing_char_Kharazim -0.0454 0.038 -1.202 0.230 -0.119 0.029
opposing_char_Leoric -0.1254 0.030 -4.128 0.000 -0.185 -0.066
opposing_char_Li Li -0.0545 0.036 -1.532 0.126 -0.124 0.015
opposing_char_Li-Ming 0.1840 0.026 6.979 0.000 0.132 0.236
opposing_char_Lt. Morales 0.0605 0.039 1.540 0.124 -0.016 0.138
opposing_char_Lunara -0.0221 0.030 -0.741 0.459 -0.081 0.036
opposing_char_Lúcio 0.0914 0.038 2.426 0.015 0.018 0.165
opposing_char_Maiev 0.0208 0.036 0.583 0.560 -0.049 0.091
opposing_char_Malfurion 0.0682 0.036 1.900 0.057 -0.002 0.139
opposing_char_Malthael -0.0655 0.033 -2.015 0.044 -0.129 -0.002
opposing_char_Medivh 0.1845 0.039 4.690 0.000 0.107 0.262
opposing_char_Muradin 0.0081 0.027 0.302 0.763 -0.044 0.061
opposing_char_Murky -0.1365 0.043 -3.204 0.001 -0.220 -0.053
opposing_char_Nazeebo -0.0181 0.027 -0.678 0.498 -0.071 0.034
opposing_char_Nova 0.0953 0.037 2.586 0.010 0.023 0.167
opposing_char_Probius -0.1713 0.062 -2.752 0.006 -0.293 -0.049
opposing_char_Ragnaros -0.0026 0.032 -0.082 0.935 -0.066 0.060
opposing_char_Raynor -0.3884 0.026 -14.951 0.000 -0.439 -0.337
opposing_char_Rehgar -0.0866 0.036 -2.389 0.017 -0.158 -0.016
opposing_char_Rexxar -0.0933 0.044 -2.134 0.033 -0.179 -0.008
opposing_char_Samuro -0.1838 0.039 -4.726 0.000 -0.260 -0.108
opposing_char_Sgt. Hammer -0.1132 0.037 -3.092 0.002 -0.185 -0.041
opposing_char_Sonya -0.0615 0.027 -2.267 0.023 -0.115 -0.008
opposing_char_Stitches 0.0741 0.028 2.681 0.007 0.020 0.128
opposing_char_Stukov 0.0402 0.037 1.101 0.271 -0.031 0.112
opposing_char_Sylvanas 0.0508 0.030 1.667 0.096 -0.009 0.111
opposing_char_Tassadar 0.3643 0.045 8.132 0.000 0.277 0.452
opposing_char_The Butcher -0.0559 0.033 -1.684 0.092 -0.121 0.009
opposing_char_The Lost Vikings -0.0413 0.064 -0.642 0.521 -0.167 0.085
opposing_char_Thrall -0.0489 0.027 -1.805 0.071 -0.102 0.004
opposing_char_Tracer 0.0342 0.031 1.118 0.264 -0.026 0.094
opposing_char_Tychus 0.0568 0.030 1.877 0.061 -0.003 0.116
opposing_char_Tyrael 0.0131 0.035 0.369 0.712 -0.056 0.083
opposing_char_Tyrande 0.0780 0.035 2.220 0.026 0.009 0.147
opposing_char_Uther 0.0353 0.038 0.930 0.352 -0.039 0.110
opposing_char_Valeera 0.1088 0.039 2.760 0.006 0.032 0.186
opposing_char_Valla 0.0462 0.028 1.649 0.099 -0.009 0.101
opposing_char_Varian -0.0215 0.026 -0.821 0.412 -0.073 0.030
opposing_char_Xul -0.0868 0.041 -2.119 0.034 -0.167 -0.007
opposing_char_Yrel -0.1498 0.028 -5.360 0.000 -0.205 -0.095
opposing_char_Zagara -0.1467 0.031 -4.781 0.000 -0.207 -0.087
opposing_char_Zarya 0.0007 0.034 0.020 0.984 -0.067 0.068
opposing_char_Zuljin -0.0294 0.030 -0.984 0.325 -0.088 0.029
allied_avg_mrr**2 3.066e-07 4.52e-08 6.784 0.000 2.18e-07 3.95e-07
allied_avg_hero_level**2 0.0002 0.000 0.468 0.640 -0.001 0.001
opp_avg_hero_level**2 -0.0002 0.000 -0.468 0.640 -0.001 0.001
opp_avg_mrr**2 -3.066e-07 4.52e-08 -6.784 0.000 -3.95e-07 -2.18e-07
In [46]:
x = results.params.filter(like='allied_char')
In [57]:
y = pd.Series({c:obs.loc[obs[c].astype(bool)]['outcome'].mean() for c in x.index})
y_std = pd.Series({c:obs.loc[obs[c].astype(bool)]['outcome'].std()/np.sqrt(obs[c].astype(bool).sum()) for c in x.index})
In [58]:
y_std
Out[58]:
allied_char_Abathur             0.005426
allied_char_Alarak              0.004501
allied_char_Alexstrasza         0.003930
allied_char_Ana                 0.004317
allied_char_Anubarak            0.004249
allied_char_Artanis             0.003510
allied_char_Arthas              0.004095
allied_char_Auriel              0.004372
allied_char_Azmodan             0.003114
allied_char_Blaze               0.004390
allied_char_Brightwing          0.003926
allied_char_Cassia              0.003930
allied_char_Chen                0.010016
allied_char_Cho                 0.010510
allied_char_Chromie             0.004225
allied_char_D.Va                0.007085
allied_char_Deckard             0.003400
allied_char_Dehaka              0.003521
allied_char_Diablo              0.002510
allied_char_E.T.C.              0.003601
allied_char_Falstad             0.003780
allied_char_Fenix               0.003235
allied_char_Garrosh             0.003781
allied_char_Gazlowe             0.007034
allied_char_Genji               0.003467
allied_char_Greymane            0.004101
allied_char_Guldan              0.003194
allied_char_Hanzo               0.003822
allied_char_Illidan             0.006329
allied_char_Jaina               0.002703
allied_char_Johanna             0.002820
allied_char_Junkrat             0.005079
allied_char_Kaelthas            0.002880
allied_char_KelThuzad           0.004766
allied_char_Kerrigan            0.006168
allied_char_Kharazim            0.004638
allied_char_Leoric              0.004614
allied_char_Li Li               0.002817
allied_char_Li-Ming             0.002857
allied_char_Lt. Morales         0.004911
allied_char_Lunara              0.004558
allied_char_Lúcio               0.004135
allied_char_Maiev               0.006647
allied_char_Malfurion           0.002918
allied_char_Malthael            0.005585
allied_char_Medivh              0.007731
allied_char_Muradin             0.002341
allied_char_Murky               0.008671
allied_char_Nazeebo             0.003126
allied_char_Nova                0.006993
allied_char_Probius             0.014002
allied_char_Ragnaros            0.005342
allied_char_Raynor              0.002663
allied_char_Rehgar              0.003247
allied_char_Rexxar              0.008937
allied_char_Samuro              0.007627
allied_char_Sgt. Hammer         0.006855
allied_char_Sonya               0.003321
allied_char_Stitches            0.002956
allied_char_Stukov              0.003439
allied_char_Sylvanas            0.004782
allied_char_Tassadar            0.008974
allied_char_The Butcher         0.005780
allied_char_The Lost Vikings    0.014610
allied_char_Thrall              0.003471
allied_char_Tracer              0.004903
allied_char_Tychus              0.004678
allied_char_Tyrael              0.006352
allied_char_Tyrande             0.006253
allied_char_Uther               0.004385
allied_char_Valeera             0.007837
allied_char_Valla               0.003769
allied_char_Varian              0.002628
allied_char_Xul                 0.008215
allied_char_Yrel                0.003548
allied_char_Zagara              0.004847
allied_char_Zarya               0.006100
allied_char_Zuljin              0.004572
dtype: float64
In [48]:
%matplotlib inline
from matplotlib import pyplot as plt
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('retina')
plt.style.use('bmh')

f, ax = plt.subplots(1,1,figsize=(12,12))
ax.scatter(x, y)

for i, txt in enumerate(x.index):
    txt = txt.lstrip("allied_char_")
    ax.annotate(txt, (x[i]+0.005, y[i]), fontsize=9)
    
#ax.set_ylabel("<--- lower naive winrate | higher naive winrate --->")

plt.hlines(0.5, -0.5, 0.5, lw=1, color='gray')
plt.vlines(0.0, 0.38, 0.6, lw=1, color='gray')

plt.xlim(-0.5, 0.5)
plt.ylim(0.38, 0.6)

ax.text(-0.025, 0.59, 'higher naive win rate -->', style='italic', rotation=90, fontsize=13)
ax.text(-0.025, 0.44, '<-- lower naive win rate', style='italic', rotation=90, fontsize=13)
ax.text(0.22, 0.503, 'higher causal win rate -->', style='italic', fontsize=13)
ax.text(-0.465, 0.503, '<-- lower causal win rate', style='italic', fontsize=13)


plt.ylabel("Naive win rate")
plt.xlabel("Causal win rate")

plt.savefig("causal_v_naive.png", bbox_inches='tight')
In [49]:
pd.DataFrame({'naive': y, 'causal': x}).to_csv("20180710_results.csv")
In [37]:
f, ax = plt.subplots(1,1,figsize=(15,12))

yerr = results.bse.filter(like='allied_char')

r = pd.DataFrame({'param': x, 'error': 1.96*yerr})
r.index = [_.lstrip('allied_char_') for _ in r.index]

r.sort_values('param').plot.barh(y='param', ax=ax, color='#348ABD', xerr='error', lw=0.1)
plt.savefig("coefs.png", bbox_inches='tight')
In [22]:
x.sort_values().index[int(len(x)/2)]
Out[22]:
'allied_char_Zeratul'