Skip to content

Commit 5ff770b

Browse files
committed
Partie ML plus esthétique
1 parent ff0820b commit 5ff770b

File tree

7 files changed

+125
-262
lines changed

7 files changed

+125
-262
lines changed

_quarto.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ project:
77
- content/getting-started/index.qmd
88
- content/manipulation/index.qmd
99
- content/visualisation/index.qmd
10-
- content/visualisation/maps.qmd
1110
- content/modelisation/index.qmd
12-
- content/modelisation/3_regression.qmd
1311
- content/NLP/index.qmd
14-
- content/modern-ds/s3.qmd
1512
- content/annexes/corrections.qmd
1613
- content/annexes/evaluation.qmd
1714
- content/git/*.qmd

content/annexes/corrections.qmd

Lines changed: 70 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,95 +23,118 @@ defaultPrint = (isBetweenSeptAndDec() === false)
2323

2424
# Partie 1: manipuler des données
2525

26+
2627
* [Retour sur `Numpy`](https://github.com/linogaliana/python-datascientist-notebooks/blob/main/corrections/manipulation/01_numpy.ipynb)
2728

28-
```{ojs}
29-
renderCorrection({fpath: "content/manipulation/01_numpy.qmd", correction: true})
30-
```
29+
{{< badges
30+
fpath="/content/manipulation/01_numpy.qmd"
31+
printMessage="false"
32+
correction="true"
33+
>}}
3134
3235
* [Introduction à `Pandas`](../manipulation/02_pandas_intro.qmd)
3336

34-
```{ojs}
35-
renderCorrection({fpath: "content/manipulation/02_pandas_intro.qmd", correction: true})
36-
```
37+
{{< badges
38+
fpath="/content/manipulation/02_pandas_intro.qmd"
39+
printMessage="false"
40+
correction="true"
41+
>}}
3742
3843
* [Manipulations de données avec `Pandas`](../manipulation/02_pandas_suite.qmd)
3944

40-
```{ojs}
41-
renderCorrection({fpath: "content/manipulation/02_pandas_suite.qmd", correction: true})
42-
```
43-
45+
{{< badges
46+
fpath="/content/manipulation/02_pandas_suite.qmd"
47+
printMessage="false"
48+
correction="true"
49+
>}}
4450
45-
* [Exercices `Geopandas`](../manipulation/03_geopandas_TP.qmd) :
51+
* [Exercices `Geopandas`](../manipulation/03_geopandas_TP.qmd)
4652

47-
```{ojs}
48-
renderCorrection({fpath: "content/manipulation/03_geopandas_TP.qmd", correction: true})
49-
```
53+
{{< badges
54+
fpath="/content/manipulation/03_geopandas_TP.qmd"
55+
printMessage="false"
56+
correction="true"
57+
>}}
5058
5159
* [Exercices _webscraping_](../manipulation/04a_webscraping_TP.qmd)
5260

53-
```{ojs}
54-
renderCorrection({fpath: "content/manipulation/04a_webscraping_TP.qmd", correction: true})
55-
```
56-
61+
{{< badges
62+
fpath="/content/manipulation/04a_webscraping_TP.qmd"
63+
printMessage="false"
64+
correction="true"
65+
>}}
5766
5867
* [Exercices expressions régulières](../manipulation/04b_regex_TP.qmd)
5968

60-
```{ojs}
61-
renderCorrection({fpath: "content/manipulation/04b_regex_TP.qmd", correction: true})
62-
```
63-
69+
{{< badges
70+
fpath="/content/manipulation/04b_regex_TP.qmd"
71+
printMessage="false"
72+
correction="true"
73+
>}}
6474
6575
* [Exercices API](../manipulation/04c_API_TP.qmd)
6676

67-
```{ojs}
68-
renderCorrection({fpath: "content/manipulation/04c_API_TP.qmd", correction: true})
69-
```
77+
{{< badges
78+
fpath="/content/manipulation/04c_API_TP.qmd"
79+
printMessage="false"
80+
correction="true"
81+
>}}
82+
7083

7184
# Partie 2: visualiser les données
7285

73-
* [Exercices graphiques classiques](../visualisation/matplotlib.qmd)
7486

75-
```{ojs}
76-
renderCorrection({fpath: "content/visualisation/matplotlib.qmd", correction: defaultPrint})
77-
```
87+
* [Exercices graphiques classiques](../visualisation/matplotlib.qmd)
7888

89+
{{< badges
90+
fpath="/content/visualisation/matplotlib.qmd"
91+
printMessage="false"
92+
correction="true"
93+
>}}
7994
8095
* [Exercices sur la cartographie](../visualisation/maps.qmd)
8196

82-
```{ojs}
83-
renderCorrection({fpath: "content/visualisation/maps.qmd", correction: defaultPrint})
84-
```
85-
97+
{{< badges
98+
fpath="/content/visualisation/maps.qmd"
99+
printMessage="false"
100+
correction="true"
101+
>}}
86102
87103

88104
# Partie 3: modéliser
89105

106+
90107
* [Exercices sur le _preprocessing_](../modelisation/0_preprocessing.qmd)
91108

92-
```{ojs}
93-
renderCorrection({fpath: "content/modelisation/0_preprocessing.qmd", correction: defaultPrint})
94-
```
109+
{{< badges
110+
fpath="/content/modelisation/0_preprocessing.qmd"
111+
printMessage="false"
112+
correction="true"
113+
>}}
95114
96115
* [Exercices sur l'évaluation des modèles](../modelisation/1_modelevaluation.qmd)
97116

98-
```{ojs}
99-
renderCorrection({fpath: "content/modelisation/1_modelevaluation.qmd", correction: defaultPrint})
100-
```
101-
117+
{{< badges
118+
fpath="/content/modelisation/1_modelevaluation.qmd"
119+
printMessage="false"
120+
correction="true"
121+
>}}
102122
103123
* [Exercices sur la classification](../modelisation/2_SVM.qmd)
104124

105-
```{ojs}
106-
renderCorrection({fpath: "content/modelisation/2_SVM.qmd", correction: defaultPrint})
107-
```
125+
{{< badges
126+
fpath="/content/modelisation/2_SVM.qmd"
127+
printMessage="false"
128+
correction="true"
129+
>}}
108130
109131
* [Exercices sur la régression](../modelisation/3_regression.qmd)
110132

111-
112-
```{ojs}
113-
renderCorrection({fpath: "content/modelisation/3_regression.qmd", correction: defaultPrint})
114-
```
133+
{{< badges
134+
fpath="/content/modelisation/3_regression.qmd"
135+
printMessage="false"
136+
correction="true"
137+
>}}
115138
116139
* [Exercices sur la sélection de variables](../modelisation/4_featureselection.qmd)
117140

content/modelisation/4_featureselection.qmd

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
---
22
title: "Sélection de variables : une introduction"
3-
draft: false
4-
weight: 50
5-
slug: lasso
6-
type: book
7-
tags:
8-
- scikit
9-
- machine learning
10-
- US elections
11-
- LASSO
12-
- feature selection
13-
- Modélisation
14-
- Exercice
153
categories:
164
- Modélisation
175
- Exercice
@@ -31,11 +19,9 @@ echo: false
3119
---
3220

3321

34-
35-
36-
::: {.content-visible when-format="html"}
37-
{{< include "../../build/_printBadges.qmd" >}}
38-
:::
22+
{{< badges
23+
printMessage="true"
24+
>}}
3925
4026

4127

@@ -113,7 +99,7 @@ $$
11399
\text{s.t. } \sum_{j=1}^p |\beta_j| \leq t
114100
$$
115101

116-
Ce programme se reformule grâce au Lagrangien est permet ainsi d'obtenir un programme de minimisation plus maniable :
102+
Ce programme se reformule grâce au Lagrangien et permet ainsi d'obtenir un programme de minimisation plus maniable :
117103

118104
$$
119105
\beta^{\text{LASSO}} = \arg \min_{\beta} \frac{1}{2}\mathbb{E}\bigg( \big( X\beta - y \big)^2 \bigg) + \alpha \sum_{j=1}^p |\beta_j| = \arg \min_{\beta} ||y-X\beta||_{2}^{2} + \lambda ||\beta||_1
@@ -197,11 +183,8 @@ def extract_features_selected(lasso: Pipeline, preprocessing_step_name: str = 'p
197183
return features_selec
198184
```
199185

200-
::: {.cell .markdown}
201-
```{=html}
202-
<div class="alert alert-success" role="alert">
203-
<h3 class="alert-heading"><i class="fa-solid fa-pencil"></i> Exercice 1 : Premier LASSO</h3>
204-
```
186+
::: {.exercise}
187+
## Exercice 1 : Premier LASSO
205188

206189
On cherche toujours à prédire la variable `per_gop`. Avant de faire notre estimation, nous allons créer certains objets intermédiaires qui seront utilisés pour
207190
définir notre _pipeline_:
@@ -273,9 +256,6 @@ preprocessor = ColumnTransformer(transformers=[
273256
</details>
274257

275258

276-
```{=html}
277-
</div>
278-
```
279259
:::
280260

281261

@@ -515,19 +495,12 @@ preprocessed_features = pd.DataFrame(
515495

516496

517497

518-
::: {.cell .markdown}
519-
```{=html}
520-
<div class="alert alert-success" role="alert">
521-
<h3 class="alert-heading"><i class="fa-solid fa-pencil"></i> Exercice 2 : Rôle du paramètre de pénalisation</h3>
522-
```
498+
::: {.exercise}
499+
## Exercice 2 : Rôle du paramètre de pénalisation
523500

524501
Utiliser la fonction `lasso_path` pour évaluer le nombre de paramètres sélectionnés par LASSO lorsque $\alpha$
525502
varie (parcourir $\alpha \in [0.001,0.01,0.02,0.025,0.05,0.1,0.25,0.5,0.8,1.0]$ ).
526503

527-
528-
```{=html}
529-
</div>
530-
```
531504
:::
532505

533506

@@ -658,15 +631,8 @@ print(f"Cela correspond à un modèle avec {n_var_selected} variables sélection
658631
```
659632

660633

661-
::: {.cell .markdown}
662-
```{=html}
663-
<div class="alert alert-warning" role="alert">
664-
<h3 class="alert-heading"><i class="fa-solid fa-pencil"></i> Hint</h3>
665-
```
634+
::: {.tip}
666635

667636
Dans le cas où le modèle paraîtrait trop peu parcimonieux, il faudrait revoir la phase de définition des variables pertinentes pour comprendre si des échelles différentes de certaines variables ne seraient pas plus appropriées (par exemple du `log`).
668637

669-
```{=html}
670-
</div>
671-
```
672638
:::

0 commit comments

Comments
 (0)