Commit b7d24697 authored by escuiller's avatar escuiller

export code+results ok

parent e9dbda51
This diff is collapsed.
...@@ -35,7 +35,7 @@ possibly in a nicer looking way. ...@@ -35,7 +35,7 @@ possibly in a nicer looking way.
We will be using the python3 language using the pandas, statsmodels, We will be using the python3 language using the pandas, statsmodels,
numpy, matplotlib and seaborn libraries. numpy, matplotlib and seaborn libraries.
#+BEGIN_SRC python :session :export both :results output #+BEGIN_SRC python :session :exports both :results output
def print_imported_modules(): def print_imported_modules():
import sys import sys
for name, val in sorted(sys.modules.items()): for name, val in sorted(sys.modules.items()):
...@@ -61,7 +61,7 @@ print_imported_modules() ...@@ -61,7 +61,7 @@ print_imported_modules()
#+RESULTS: #+RESULTS:
#+begin_example #+begin_example
3.8.2 | packaged by conda-forge | (default, Apr 16 2020, 18:04:51) 3.8.1 (default, Jan 8 2020, 22:29:32)
[GCC 7.3.0] [GCC 7.3.0]
uname_result(system='Linux', node='hpisor', release='4.9.0-12-amd64', version='#1 SMP Debian 4.9.210-1 (2020-01-20)', machine='x86_64', processor='') uname_result(system='Linux', node='hpisor', release='4.9.0-12-amd64', version='#1 SMP Debian 4.9.210-1 (2020-01-20)', machine='x86_64', processor='')
_csv 1.0 _csv 1.0
...@@ -73,9 +73,9 @@ ctypes 1.1.0 ...@@ -73,9 +73,9 @@ ctypes 1.1.0
cycler 0.10.0 cycler 0.10.0
dateutil 2.8.1 dateutil 2.8.1
decimal 1.70 decimal 1.70
distutils 3.8.2 distutils 3.8.1
json 2.0.9 json 2.0.9
kiwisolver 1.0.1 kiwisolver 1.2.0
logging 0.5.1.2 logging 0.5.1.2
matplotlib 3.1.3 matplotlib 3.1.3
matplotlib.backends.backend_agg 3.1.3 matplotlib.backends.backend_agg 3.1.3
...@@ -92,8 +92,8 @@ pandas 1.0.3 ...@@ -92,8 +92,8 @@ pandas 1.0.3
patsy 0.5.1 patsy 0.5.1
patsy.version 0.5.1 patsy.version 0.5.1
platform 1.0.8 platform 1.0.8
pyparsing 2.4.6 pyparsing 2.4.7
pytz 2019.3 pytz 2020.1
re 2.2.1 re 2.2.1
scipy 1.4.1 scipy 1.4.1
scipy._lib._uarray 0.5.1+5.ga864a57.scipy scipy._lib._uarray 0.5.1+5.ga864a57.scipy
...@@ -144,7 +144,7 @@ Let's start by reading data. ...@@ -144,7 +144,7 @@ Let's start by reading data.
Note: url corrected based on forum post at https://www.fun-mooc.fr/courses/course-v1:inria+41016+self-paced/courseware/7bf2267c336246f9b6518db624692e14/96b7ce47bd11466a9a2e63d8e8a93d99/ Note: url corrected based on forum post at https://www.fun-mooc.fr/courses/course-v1:inria+41016+self-paced/courseware/7bf2267c336246f9b6518db624692e14/96b7ce47bd11466a9a2e63d8e8a93d99/
#+BEGIN_SRC python :session :export both :results value #+BEGIN_SRC python :session :exports both :results value
data = pd.read_csv("https://app-learninglab.inria.fr/moocrr/gitlab/moocrr-session3/moocrr-reproducibility-study/raw/master/data/shuttle.csv") data = pd.read_csv("https://app-learninglab.inria.fr/moocrr/gitlab/moocrr-session3/moocrr-reproducibility-study/raw/master/data/shuttle.csv")
data data
#+END_SRC #+END_SRC
...@@ -181,7 +181,7 @@ data ...@@ -181,7 +181,7 @@ data
We know from our previous experience on this data set that filtering We know from our previous experience on this data set that filtering
data is a really bad idea. We will therefore process it as such. data is a really bad idea. We will therefore process it as such.
#+BEGIN_SRC python :session :export both :results output #+BEGIN_SRC python :session :exports both :results output
#%matplotlib inline #%matplotlib inline
pd.set_option('mode.chained_assignment',None) # this removes a useless warning from pandas pd.set_option('mode.chained_assignment',None) # this removes a useless warning from pandas
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
...@@ -206,7 +206,7 @@ Let's assume O-rings independently fail with the same probability which ...@@ -206,7 +206,7 @@ Let's assume O-rings independently fail with the same probability which
solely depends on temperature. A logistic regression should allow us to solely depends on temperature. A logistic regression should allow us to
estimate the influence of temperature. estimate the influence of temperature.
#+BEGIN_SRC python :session :export both :results value #+BEGIN_SRC python :session :exports both :results value
import statsmodels.api as sm import statsmodels.api as sm
data["Success"]=data.Count-data.Malfunction data["Success"]=data.Count-data.Malfunction
...@@ -228,7 +228,7 @@ Model Family: Binomial Df Model: 1 ...@@ -228,7 +228,7 @@ Model Family: Binomial Df Model: 1
Link Function: logit Scale: 1.0000 Link Function: logit Scale: 1.0000
Method: IRLS Log-Likelihood: -3.9210 Method: IRLS Log-Likelihood: -3.9210
Date: mar., 05 mai 2020 Deviance: 3.0144 Date: mar., 05 mai 2020 Deviance: 3.0144
Time: 19:13:17 Pearson chi2: 5.00 Time: 22:25:31 Pearson chi2: 5.00
No. Iterations: 6 No. Iterations: 6
Covariance Type: nonrobust Covariance Type: nonrobust
=============================================================================== ===============================================================================
...@@ -252,7 +252,7 @@ for each rocket launch. Let's indicate these weights (since the weights ...@@ -252,7 +252,7 @@ for each rocket launch. Let's indicate these weights (since the weights
are always the same throughout all experiments, it does not change the are always the same throughout all experiments, it does not change the
estimates of the fit but it does influence the variance estimates). estimates of the fit but it does influence the variance estimates).
#+BEGIN_SRC python :session :export both :results value #+BEGIN_SRC python :session :exports both :results value
logmodel=sm.GLM(data['Frequency'], data[['Intercept','Temperature']], logmodel=sm.GLM(data['Frequency'], data[['Intercept','Temperature']],
family=sm.families.Binomial(sm.families.links.logit), family=sm.families.Binomial(sm.families.links.logit),
var_weights=data['Count']).fit() var_weights=data['Count']).fit()
...@@ -270,7 +270,7 @@ Model Family: Binomial Df Model: 1 ...@@ -270,7 +270,7 @@ Model Family: Binomial Df Model: 1
Link Function: logit Scale: 1.0000 Link Function: logit Scale: 1.0000
Method: IRLS Log-Likelihood: -23.526 Method: IRLS Log-Likelihood: -23.526
Date: mar., 05 mai 2020 Deviance: 18.086 Date: mar., 05 mai 2020 Deviance: 18.086
Time: 19:13:17 Pearson chi2: 30.0 Time: 22:25:31 Pearson chi2: 30.0
No. Iterations: 6 No. Iterations: 6
Covariance Type: nonrobust Covariance Type: nonrobust
=============================================================================== ===============================================================================
...@@ -297,7 +297,7 @@ of freedom (Df Residuals). ...@@ -297,7 +297,7 @@ of freedom (Df Residuals).
The temperature when launching the shuttle was 31°F. Let's try to The temperature when launching the shuttle was 31°F. Let's try to
estimate the failure probability for such temperature using our model.: estimate the failure probability for such temperature using our model.:
#+BEGIN_SRC python :session :results output :export both #+BEGIN_SRC python :session :results output :exports both
#%matplotlib inline #%matplotlib inline
data_pred = pd.DataFrame({'Temperature': np.linspace(start=30, stop=90, num=121), 'Intercept': 1}) data_pred = pd.DataFrame({'Temperature': np.linspace(start=30, stop=90, num=121), 'Intercept': 1})
data_pred['Frequency'] = logmodel.predict(data_pred) data_pred['Frequency'] = logmodel.predict(data_pred)
...@@ -323,7 +323,7 @@ Following the documentation of ...@@ -323,7 +323,7 @@ Following the documentation of
[[https://seaborn.pydata.org/generated/seaborn.regplot.html][Seaborn]], [[https://seaborn.pydata.org/generated/seaborn.regplot.html][Seaborn]],
I use regplot. I use regplot.
#+BEGIN_SRC python :session :results output :export both #+BEGIN_SRC python :session :results output :exports both
sns.set(color_codes=True) sns.set(color_codes=True)
plt.xlim(30,90) plt.xlim(30,90)
plt.ylim(0,1) plt.ylim(0,1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment