Skip to content

Commit

Permalink
Rebuild visualisation part (#357)
Browse files Browse the repository at this point in the history
* update

* Automated changes

* Automated changes

* change sens

* Automated changes

* Automated changes

* rawhtml

* Automated changes

* Automated changes

* retire folium output

* Automated changes

* Automated changes

* hide

* rm

* Automated changes

* Automated changes

* Automated changes

* Automated changes

* up

* Automated changes

* Automated changes

* eval

* Automated changes

* Automated changes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
linogaliana and github-actions[bot] committed Apr 19, 2023
1 parent fdf32e1 commit 38693f6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 89 deletions.
5 changes: 3 additions & 2 deletions build/tweak_markdown.py
Expand Up @@ -32,10 +32,11 @@ def clean_write_file(fl):
print(f"File: {fl}")
add_text = '\n\n<script src="https://d3js.org/d3.v7.min.js"></script>\n<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>'
yaml, text = content.split('---\n', 2)[1:]
incipit = "Ce contenu accompagne le cours [Python pour la data science](https://pythonds.linogaliana.fr/) de l'ENSAE. \n"
if re.search("plotly: true", yaml) is not None:
print(f"Tweaking {fl} using YAML header")
content = "---\n"+ yaml + "---\n" \
+ add_text+"\n"+text
content = "---\n" + yaml + "---\n" \
+ "\n" + incipit + add_text + "\n" + text
else:
print(f"File {fl}: nothing to do")
if re.search(
Expand Down
4 changes: 1 addition & 3 deletions content/course/manipulation/04a_webscraping_TP/index.qmd
Expand Up @@ -693,13 +693,11 @@ m.fit_bounds([sw, ne])

La carte obtenue doit ressembler à la suivante:

{{{< rawhtml >}}}
```{python}
#| echo : false
#| eval : false
# Afficher la carte
m
```
{{{< /rawhtml >}}}


# Récupérer des informations sur les pokemons
Expand Down
38 changes: 20 additions & 18 deletions content/course/manipulation/04c_API_TP/index.qmd
Expand Up @@ -39,6 +39,10 @@ print_badges("content/course/manipulation/04c_API_TP.qmd")
```
:::



__La partie utilisant l'API DVF n'est plus à jour, elle sera mise à jour prochainement__

# Introduction : Qu'est-ce qu'une API ?

## Définition
Expand Down Expand Up @@ -278,13 +282,12 @@ def interactive_map_dpe(dpe):
m = interactive_map_dpe(dpe)
```

{{{< rawhtml >}}}
```{python}
#| echo : false
#| echo : true
#| eval: false
# Afficher la carte
m
```
{{{< /rawhtml >}}}

On remarque un problème dans les données: un logement qui n'a
rien à voir avec les autres. Il faudrait donc idéalement
Expand Down Expand Up @@ -328,13 +331,12 @@ dpe_geo_filter = get_dpe_from_url(url_api)
m_geo_filter = interactive_map_dpe(dpe)
```

{{{< rawhtml >}}}
```{python}
#| echo : false
#| echo : true
#| eval: false
# Afficher la carte
m_geo_filter
```
{{{< /rawhtml >}}}

## Un catalogue incomplet d'API existantes

Expand Down Expand Up @@ -411,6 +413,7 @@ groupes par exemple
```{python}
#| echo: false
#| include: false
#| eval: false
# Question 1
import json
Expand All @@ -428,6 +431,7 @@ ressembler au `DataFrame` suivant:

```{python}
#| echo: false
#| eval: false
# Question 2
maisons = requests.get("http://api.cquest.org/dvf?code_commune=29168&type_local=Maison").json()
Expand All @@ -437,6 +441,7 @@ pd.json_normalize(maisons["resultats"])

```{python}
#| echo: false
#| eval: false
# Question 3
#!pip install geopandas
Expand All @@ -450,6 +455,7 @@ L'histogramme des prix de vente (question 4) aura l'aspect suivant:
```{python}
#| echo: false
#| include: false
#| eval: false
# Question 4
p = ventes["valeur_fonciere"].plot(kind = "hist")
Expand All @@ -466,6 +472,8 @@ convertir
en objet `geopandas`.

```{python}
#| eval: false
ventes = ventes.dropna(subset = ['lat','lon'])
ventes = gpd.GeoDataFrame(ventes, geometry=gpd.points_from_xy(ventes.lon, ventes.lat))
ventes
Expand All @@ -477,6 +485,7 @@ sa représentation avec `folium`
([voir la doc `geopandas` à ce propos](https://geopandas.readthedocs.io/en/latest/gallery/polygon_plotting_with_folium.html#Add-polygons-to-map)):

```{python}
#| eval: false
geo_j = plgf.to_json()
```

Expand All @@ -485,6 +494,7 @@ le comprendre et pas uniquement de l'exécuter).

```{python}
#| output: hide
#| eval: false
import folium
import numpy as np
Expand Down Expand Up @@ -515,18 +525,11 @@ m.fit_bounds([sw, ne])


```{python}
#| eval : false
# Afficher la carte
m
```

{{{< rawhtml >}}}
```{python}
#| echo : false
#| echo : true
#| eval: false
# Afficher la carte
m
```
{{{< /rawhtml >}}}



Expand Down Expand Up @@ -748,13 +751,12 @@ m.fit_bounds([sw, ne])

Ce qui permet d'obtenir la carte:

{{{< rawhtml >}}}
```{python}
#| echo : false
#| echo : true
#| eval: false
# Afficher la carte
m
```
{{{< /rawhtml >}}}

Vous pouvez aller plus loin avec l'exercice suivant.
Celui-ci nécessite une fonction pour créer un cercle autour d'un point (source [ici](https://gis.stackexchange.com/questions/289044/creating-buffer-circle-x-kilometers-from-point-using-python/289923)),
Expand Down
36 changes: 7 additions & 29 deletions content/course/modelisation/6_pipeline/index.qmd
Expand Up @@ -142,15 +142,12 @@ set_config(display='diagram')
pipe
~~~

{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: false
#| echo: false
print(estimator_html_repr(pipe))
```

{{{< /rawhtml >}}}

Au sein d'une étape de *pipeline*, les paramètres d'un estimateur
sont accessibles avec la notation `<estimator>__<parameter>`.
Expand All @@ -165,15 +162,12 @@ param_grid = {"reduce_dim__n_components":[2, 5, 10], "clf__C":[0.1, 10, 100]}
grid_search = GridSearchCV(pipe, param_grid=param_grid)
```

{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: asis
#| echo: false
print(estimator_html_repr(grid_search))
```

{{{< /rawhtml >}}}


## Données utilisées
Expand Down Expand Up @@ -396,15 +390,12 @@ ce _pipeline_ opère:
pipe
~~~

{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: asis
#| echo: false
print(estimator_html_repr(pipe))
```

{{{< /rawhtml >}}}


Maintenant, il ne reste plus qu'à estimer notre modèle sur l'ensemble
Expand Down Expand Up @@ -615,16 +606,12 @@ end_time = time.time()
print("Elapsed time : {} seconds", int(end_time - start_time))
```

{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: false
#| echo: false
print(estimator_html_repr(grid_search))
```

{{{< /rawhtml >}}}

```{python}
#| echo: false
print("Elapsed time : {} seconds", int(end_time - start_time))
Expand All @@ -644,15 +631,12 @@ grid_search.best_estimator_
~~~


{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: false
#| echo: false
print(estimator_html_repr(grid_search.best_estimator_))
```

{{{< /rawhtml >}}}

Toutes les performances sur les ensembles d'échantillons et de test sur la grille
d'hyperparamètres sont disponibles dans l'attribut:
Expand Down Expand Up @@ -970,15 +954,12 @@ pipe2 = Pipeline([
])
```

{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: false
#| echo: false
print(estimator_html_repr(pipe2))
```

{{{< /rawhtml >}}}

```{python}
preprocessor = ColumnTransformer(
Expand All @@ -990,15 +971,12 @@ pipe3 = Pipeline(steps=[('preprocessor', preprocessor),
('randomforest', regr)])
```

{{{< rawhtml >}}}

```{python}
#| output: asis
#| eval: false
#| echo: false
print(estimator_html_repr(pipe3))
```

{{{< /rawhtml >}}}

# Références

Expand Down

0 comments on commit 38693f6

Please sign in to comment.