-
Notifications
You must be signed in to change notification settings - Fork 0
/
6MeasuresOfFit.py
44 lines (37 loc) · 1.26 KB
/
6MeasuresOfFit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Fitting the xG model
Need to run 3xGModel.py first to load data.
Then 5xGModelFit.py to fit the model.
"""
#Mcfaddens Rsquared for Logistic regression
null_model = smf.glm(formula="Goal ~ 1 ", data=shots_model,
family=sm.families.Binomial()).fit()
1-test_model.llf/null_model.llf
#ROC curve
numobs=100
TP=np.zeros(numobs)
FP=np.zeros(numobs)
TN=np.zeros(numobs)
FN=np.zeros(numobs)
for i,threshold in enumerate(np.arange(0,1,1/numobs)):
for j,shot in shots_model.iterrows():
if (shot['Goal']==1):
if(shot['xG']>threshold):
TP[i] = TP[i] + 1
else:
FN[i] = FN[i] + 1
if (shot['Goal']==0):
if(shot['xG']>threshold):
FP[i] = FP[i] + 1
else:
TN[i] = TN[i] + 1
fig,ax=plt.subplots(num=1)
ax.plot(FP/(FP+TN), TP/(TP+FN), color='black')
ax.plot([0,1], [0,1], linestyle='dotted', color='black')
ax.set_ylabel("Predicted to score and did TP/(TP+FN))")
ax.set_xlabel("Predicted to score but didn't FP/(FP+TN)")
plt.ylim((0.00,1.00))
plt.xlim((0.00,1.00))
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
fig.savefig('Output/ROC_' + model + '.pdf', dpi=None, bbox_inches="tight")