Skip to content

Commit

Permalink
Corrections partie ML (#468)
Browse files Browse the repository at this point in the history
* corrige erreur

* highlightinh

* mef

* updaye

* Visualiseur

* clean

* return

* mef

* update
  • Loading branch information
linogaliana committed Dec 4, 2023
1 parent cf91965 commit 417fb66
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 160 deletions.
33 changes: 24 additions & 9 deletions content/annexes/corrections.qmd
Expand Up @@ -62,7 +62,7 @@ print_badges("content/manipulation/03_geopandas_TP.qmd", correction=True)
```
:::

Webscraping
* [Exercices _webscraping_](../manipulation/04a_webscraping.qmd)

::: {.cell .markdown}
```{python}
Expand All @@ -74,7 +74,9 @@ print_badges("content/manipulation/04a_webscraping_TP.qmd", correction=True)
```
:::

Expressions régulières:

* [Exercices expressions régulières](../manipulation/04b_regex_TP.qmd)


::: {.cell .markdown}
```{python}
Expand All @@ -86,7 +88,8 @@ print_badges("content/manipulation/04b_regex_TP.qmd", correction=True)
```
:::

Chapitre sur les API:
* [Exercices API](../manipulation/04c_API_TP.qmd)


::: {.cell .markdown}
```{python}
Expand All @@ -100,56 +103,68 @@ print_badges("content/manipulation/04c_API_TP.qmd", correction=True)

## Partie 2: visualiser les données

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

::: {.cell .markdown}
```{python}
#| echo: false
#| echo: true
#| output: 'asis'
#| include: true
#| eval: false
#| eval: true
print_badges("content/visualisation/matplotlib.qmd", correction=True)
```
:::

* [Exercices sur la cartographie](../visualisation/maps.qmd)

::: {.cell .markdown}
```{python}
#| echo: false
#| output: 'asis'
#| include: true
#| eval: false
#| eval: true
print_badges("content/visualisation/maps.qmd", correction=True)
```
:::


## Partie 3: modéliser

* [Exercices sur le _preprocessing_](../modelisation/0_preprocessing.qmd)


::: {.cell .markdown}
```{python}
#| echo: false
#| output: 'asis'
#| include: true
#| eval: false
#| eval: true
print_badges("content/modelisation/0_preprocessing.qmd", correction=True)
```
:::

* [Exercices sur l'évaluation des modèles](../modelisation/1_modelevaluation.qmd)


::: {.cell .markdown}
```{python}
#| echo: false
#| output: 'asis'
#| include: true
#| eval: false
#| eval: true
print_badges("content/modelisation/1_modelevaluation.qmd", correction=True)
```
:::

* [Exercices sur la classification](../modelisation/2_SVM.qmd)


::: {.cell .markdown}
```{python}
#| echo: false
#| output: 'asis'
#| include: true
#| eval: false
#| eval: true
print_badges("content/modelisation/2_SVM.qmd", correction=True)
```
:::
Expand Down
11 changes: 11 additions & 0 deletions content/modelisation/0_preprocessing.qmd
Expand Up @@ -181,6 +181,7 @@ par comté x année avec en colonnes les résultats de chaque candidat dans cet

Si vous ne faites pas l'exercice 1, pensez à charger les données en executant la fonction `get_data.py` :

::: {.python}
```{python}
#| echo: true
#| output: false
Expand All @@ -194,6 +195,8 @@ open('getdata.py', 'wb').write(r.content)
import getdata
votes = getdata.create_votes_dataframes()
```
:::


Ce code introduit une base nommée `votes` dans l'environnement. Il s'agit d'une
base rassemblant les différentes sources. Elle a l'aspect
Expand Down Expand Up @@ -346,6 +349,9 @@ ainsi que les relations entre les variables explicatives.
<h3 class="alert-heading"><i class="fa-solid fa-pencil"></i> Exercice 2 : Regarder les corrélations entre les variables</h3>
```

__Cet exercice est OPTIONNEL__


1. Créer un DataFrame `df2` plus petit avec les variables `winner`, `votes_gop`, `Unemployment_rate_2019`,
`Median_Household_Income_2019`,
`Percent of adults with less than a high school diploma, 2015-19`,
Expand All @@ -361,6 +367,7 @@ ainsi que les relations entre les variables explicatives.

```{python}
#| output: false
#| echo: true
# 1. Créer le data.frame df2.
df2 = votes.set_index("GEOID").loc[: , ["winner", "votes_gop",
Expand All @@ -371,6 +378,8 @@ df2 = votes.set_index("GEOID").loc[: , ["winner", "votes_gop",

```{python}
#| output: false
#| echo: true
# 2. Matrice de corrélation graphique
g1 = sns.heatmap(df2.drop("winner", axis = 1).corr(), cmap='coolwarm', annot=True, fmt=".2f")
Expand All @@ -394,6 +403,7 @@ g2
Le nuage de point obtenu à l'issue de la question 3 ressemblera à :

```{python}
#| echo: true
# 3. Matrice de nuages de points
ax = pd.plotting.scatter_matrix(df2, figsize = (15,15))
```
Expand All @@ -406,6 +416,7 @@ Le résultat de la question 4 devrait, quant à lui,
ressembler au graphique suivant :

```{python}
#| echo: true
# 4. Matrice de corrélation avec plotly
import plotly
import plotly.express as px
Expand Down
4 changes: 3 additions & 1 deletion content/modelisation/2_SVM.qmd
Expand Up @@ -57,6 +57,7 @@ Le code
est disponible [sur `Github`](https://github.com/linogaliana/python-datascientist/blob/master/content/modelisation/get_data.py).


::: {.python}
```{python}
#| echo: true
#| output: false
Expand All @@ -70,6 +71,7 @@ open('getdata.py', 'wb').write(r.content)
import getdata
votes = getdata.create_votes_dataframes()
```
:::


Pour ce TP, nous aurons besoin des packages suivants :
Expand Down Expand Up @@ -207,7 +209,7 @@ créer des échantillons de test (20 % des observations) et d'estimation (80 %)

5. Refaire les questions précédentes avec des variables normalisées. Le résultat est-il différent ?

6. Changer de variables *x*. Utiliser uniquement le résultat passé du vote démocrate et le revenu (`votes_gop` et `Median_Household_Income_2019`). Regarder les résultats, notamment la matrice de confusion.
6. Changer de variables *x*. Utiliser uniquement le résultat passé du vote démocrate (année 2016) et le revenu. Les variables en question sont `share_2016_republican` et `Median_Household_Income_2019`. Regarder les résultats, notamment la matrice de confusion.

7. [OPTIONNEL] Faire une 5-fold validation croisée pour déterminer le paramètre *C* idéal.

Expand Down

0 comments on commit 417fb66

Please sign in to comment.