Skip to content

Commit 38693f6

Browse files
Rebuild visualisation part (#357)
* 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>
1 parent fdf32e1 commit 38693f6

File tree

5 files changed

+72
-89
lines changed

5 files changed

+72
-89
lines changed

build/tweak_markdown.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def clean_write_file(fl):
3232
print(f"File: {fl}")
3333
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>'
3434
yaml, text = content.split('---\n', 2)[1:]
35+
incipit = "Ce contenu accompagne le cours [Python pour la data science](https://pythonds.linogaliana.fr/) de l'ENSAE. \n"
3536
if re.search("plotly: true", yaml) is not None:
3637
print(f"Tweaking {fl} using YAML header")
37-
content = "---\n"+ yaml + "---\n" \
38-
+ add_text+"\n"+text
38+
content = "---\n" + yaml + "---\n" \
39+
+ "\n" + incipit + add_text + "\n" + text
3940
else:
4041
print(f"File {fl}: nothing to do")
4142
if re.search(

content/course/manipulation/04a_webscraping_TP/index.qmd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,13 +693,11 @@ m.fit_bounds([sw, ne])
693693

694694
La carte obtenue doit ressembler à la suivante:
695695

696-
{{{< rawhtml >}}}
697696
```{python}
698-
#| echo : false
697+
#| eval : false
699698
# Afficher la carte
700699
m
701700
```
702-
{{{< /rawhtml >}}}
703701

704702

705703
# Récupérer des informations sur les pokemons

content/course/manipulation/04c_API_TP/index.qmd

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ print_badges("content/course/manipulation/04c_API_TP.qmd")
3939
```
4040
:::
4141

42+
43+
44+
__La partie utilisant l'API DVF n'est plus à jour, elle sera mise à jour prochainement__
45+
4246
# Introduction : Qu'est-ce qu'une API ?
4347

4448
## Définition
@@ -278,13 +282,12 @@ def interactive_map_dpe(dpe):
278282
m = interactive_map_dpe(dpe)
279283
```
280284

281-
{{{< rawhtml >}}}
282285
```{python}
283-
#| echo : false
286+
#| echo : true
287+
#| eval: false
284288
# Afficher la carte
285289
m
286290
```
287-
{{{< /rawhtml >}}}
288291

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

331-
{{{< rawhtml >}}}
332334
```{python}
333-
#| echo : false
335+
#| echo : true
336+
#| eval: false
334337
# Afficher la carte
335338
m_geo_filter
336339
```
337-
{{{< /rawhtml >}}}
338340

339341
## Un catalogue incomplet d'API existantes
340342

@@ -411,6 +413,7 @@ groupes par exemple
411413
```{python}
412414
#| echo: false
413415
#| include: false
416+
#| eval: false
414417
415418
# Question 1
416419
import json
@@ -428,6 +431,7 @@ ressembler au `DataFrame` suivant:
428431

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

438442
```{python}
439443
#| echo: false
444+
#| eval: false
440445
441446
# Question 3
442447
#!pip install geopandas
@@ -450,6 +455,7 @@ L'histogramme des prix de vente (question 4) aura l'aspect suivant:
450455
```{python}
451456
#| echo: false
452457
#| include: false
458+
#| eval: false
453459
454460
# Question 4
455461
p = ventes["valeur_fonciere"].plot(kind = "hist")
@@ -466,6 +472,8 @@ convertir
466472
en objet `geopandas`.
467473

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

479487
```{python}
488+
#| eval: false
480489
geo_j = plgf.to_json()
481490
```
482491

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

486495
```{python}
487496
#| output: hide
497+
#| eval: false
488498
import folium
489499
import numpy as np
490500
@@ -515,18 +525,11 @@ m.fit_bounds([sw, ne])
515525

516526

517527
```{python}
518-
#| eval : false
519-
# Afficher la carte
520-
m
521-
```
522-
523-
{{{< rawhtml >}}}
524-
```{python}
525-
#| echo : false
528+
#| echo : true
529+
#| eval: false
526530
# Afficher la carte
527531
m
528532
```
529-
{{{< /rawhtml >}}}
530533

531534

532535

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

749752
Ce qui permet d'obtenir la carte:
750753

751-
{{{< rawhtml >}}}
752754
```{python}
753-
#| echo : false
755+
#| echo : true
756+
#| eval: false
754757
# Afficher la carte
755758
m
756759
```
757-
{{{< /rawhtml >}}}
758760

759761
Vous pouvez aller plus loin avec l'exercice suivant.
760762
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)),

content/course/modelisation/6_pipeline/index.qmd

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,12 @@ set_config(display='diagram')
142142
pipe
143143
~~~
144144

145-
{{{< rawhtml >}}}
146-
147145
```{python}
148-
#| output: asis
146+
#| eval: false
149147
#| echo: false
150148
print(estimator_html_repr(pipe))
151149
```
152150

153-
{{{< /rawhtml >}}}
154151

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

168-
{{{< rawhtml >}}}
169-
170165
```{python}
171-
#| output: asis
166+
#| eval: asis
172167
#| echo: false
173168
print(estimator_html_repr(grid_search))
174169
```
175170

176-
{{{< /rawhtml >}}}
177171

178172

179173
## Données utilisées
@@ -396,15 +390,12 @@ ce _pipeline_ opère:
396390
pipe
397391
~~~
398392

399-
{{{< rawhtml >}}}
400-
401393
```{python}
402-
#| output: asis
394+
#| eval: asis
403395
#| echo: false
404396
print(estimator_html_repr(pipe))
405397
```
406398

407-
{{{< /rawhtml >}}}
408399

409400

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

618-
{{{< rawhtml >}}}
619-
620609
```{python}
621-
#| output: asis
610+
#| eval: false
622611
#| echo: false
623612
print(estimator_html_repr(grid_search))
624613
```
625614

626-
{{{< /rawhtml >}}}
627-
628615
```{python}
629616
#| echo: false
630617
print("Elapsed time : {} seconds", int(end_time - start_time))
@@ -644,15 +631,12 @@ grid_search.best_estimator_
644631
~~~
645632

646633

647-
{{{< rawhtml >}}}
648-
649634
```{python}
650-
#| output: asis
635+
#| eval: false
651636
#| echo: false
652637
print(estimator_html_repr(grid_search.best_estimator_))
653638
```
654639

655-
{{{< /rawhtml >}}}
656640

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

973-
{{{< rawhtml >}}}
974-
975957
```{python}
976-
#| output: asis
958+
#| eval: false
977959
#| echo: false
978960
print(estimator_html_repr(pipe2))
979961
```
980962

981-
{{{< /rawhtml >}}}
982963

983964
```{python}
984965
preprocessor = ColumnTransformer(
@@ -990,15 +971,12 @@ pipe3 = Pipeline(steps=[('preprocessor', preprocessor),
990971
('randomforest', regr)])
991972
```
992973

993-
{{{< rawhtml >}}}
994-
995974
```{python}
996-
#| output: asis
975+
#| eval: false
997976
#| echo: false
998977
print(estimator_html_repr(pipe3))
999978
```
1000979

1001-
{{{< /rawhtml >}}}
1002980

1003981
# Références
1004982

0 commit comments

Comments
 (0)