From b558b4a1ebd88f4cc65cc94c2b7256f335779c77 Mon Sep 17 00:00:00 2001 From: Marie-Gabrielle Dondon <85bc36e0a8096c618fbd5993d1cca191@app-learninglab.inria.fr> Date: Mon, 12 Nov 2018 16:23:40 +0000 Subject: [PATCH] Replace challenger_Python_org.org --- src/Python3/challenger_Python_org.org | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Python3/challenger_Python_org.org b/src/Python3/challenger_Python_org.org index 7d5351d..699e8fa 100644 --- a/src/Python3/challenger_Python_org.org +++ b/src/Python3/challenger_Python_org.org @@ -90,7 +90,7 @@ logmodel=sm.GLM(data['Frequency'], data[['Intercept','Temperature']], print(logmodel.summary()) #+end_src -The maximum likelyhood estimator of the intercept and of Temperature + The maximum likelyhood estimator of the intercept and of Temperature are thus *$\hat{\alpha}$ = 5.0850* and *$\hat{\beta}$ = -0.1156*. This *corresponds* to the values from the article of Dalal /et al./ The standard errors are /$s_{\hat{\alpha}}$ = 7.477/ and /$s_{\hat{\beta}}$ = 0.115/, which is *different* from @@ -128,6 +128,7 @@ print(logmodel.summary()) %matplotlib inline data_pred = pd.DataFrame({'Temperature': np.linspace(start=30, stop=90, num=121), 'Intercept': 1}) data_pred['Frequency'] = logmodel.predict(data_pred) + data_pred.plot(x="Temperature",y="Frequency",kind="line",ylim=[0,1]) plt.scatter(x=data["Temperature"],y=data["Frequency"]) plt.grid(True) @@ -136,6 +137,33 @@ plt.savefig(matplot_lib_filename) matplot_lib_filename #+end_src + #+begin_src python :results output :session :exports both +print(data_pred.head()) + #+end_src + + La fonction logmodel.predict(=data_pred=) ne fonctionne pas correctement (Frequency = 1 pour toutes les + températures). + + On peut alors utiliser le code suivant pour calculer les prédictions + et tracer la courbe : + + #+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file "figure" ".png") :exports both +# Inspiring from http://blog.yhat.com/posts/logistic-regression-and-python.html +%matplotlib inline +def logit_inv(x): + return(np.exp(x)/(np.exp(x)+1)) + +data_pred['Prob']=logit_inv(data_pred['Temperature'] * logmodel.params['Temperature'] + logmodel.params['Intercept']) +print(data_pred.head()) + +data_pred.plot(x="Temperature",y="Prob",kind="line",ylim=[0,1]) +plt.scatter(x=data["Temperature"],y=data["Frequency"]) +plt.grid(True) + +plt.savefig(matplot_lib_filename) +matplot_lib_filename +#+end_src + This figure is very similar to the Figure 4 of Dalal /et al./ *I have managed to replicate the Figure 4 of the Dalal /et al./ article.* -- 2.18.1