Skip to content

Commit 5fe455b

Browse files
committed
pagerank-thrones executes more smoothly
1 parent d5bae65 commit 5fe455b

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

notebooks/tps/pagerank-thrones/.teacher/README-pagerank-thrones-corrige-nb.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ one way to think about this problem is to create a class `RandomWalker`:
208208
* from all the above, it is easy to write the simulation
209209
* result is a dictionary with vertices as key, and as value
210210
the number of steps spent in that vertex during the simulation
211-
212211

213212
+++
214213

@@ -227,6 +226,10 @@ this radically different approach requires more care, but can then be drasticall
227226

228227
### data acquisition
229228

229+
```{code-cell} ipython3
230+
import pandas as pd
231+
```
232+
230233
```{code-cell} ipython3
231234
URL = "https://raw.githubusercontent.com/pupimvictor/NetworkOfThrones/master/stormofswords.csv"
232235
```
@@ -239,8 +242,6 @@ URL = "https://raw.githubusercontent.com/pupimvictor/NetworkOfThrones/master/sto
239242
```{code-cell} ipython3
240243
# prune-cell
241244
242-
import pandas as pd
243-
244245
df = pd.read_csv(URL)
245246
df.head()
246247
```
@@ -437,30 +438,39 @@ class PageRankWalker:
437438
if you've followed our interface, you can use the following code as-is
438439

439440
```{code-cell} ipython3
441+
:tags: [raises-exception]
442+
440443
# create a walker object from the graph obtained above
441444
442445
walker = PageRankWalker(G)
443446
```
444447

445448
```{code-cell} ipython3
446449
:cell_style: split
450+
:tags: [raises-exception]
447451
448452
STEPS = 1000
449453
450454
frequencies = walker.walk(STEPS)
451455
```
452456

453457
```{code-cell} ipython3
458+
:tags: [raises-exception]
459+
454460
# the sum of all values should be STEPS
455461
raincheck = sum(frequencies.values())
456462
raincheck == STEPS
457463
```
458464

459465
```{code-cell} ipython3
466+
:tags: [raises-exception]
467+
460468
raincheck, STEPS
461469
```
462470

463471
```{code-cell} ipython3
472+
:tags: [raises-exception]
473+
464474
# dicts are not so good at sorting
465475
# let's use a list instead
466476
@@ -530,13 +540,17 @@ def monte_carlo(url_or_filename, steps, damping=0.85):
530540
```
531541

532542
```{code-cell} ipython3
543+
:tags: [raises-exception]
544+
533545
# show top winners with a 1000-steps simu
534546
for _ in range(5):
535547
print(f"{40*'-'}")
536548
monte_carlo(URL, 1000)
537549
```
538550

539551
```{code-cell} ipython3
552+
:tags: [raises-exception]
553+
540554
# same with a tenfold simulation
541555
for _ in range(5):
542556
print(f"{40*'-'}")
@@ -572,6 +586,8 @@ from graphviz import Digraph
572586
```
573587

574588
```{code-cell} ipython3
589+
:tags: [raises-exception]
590+
575591
gv = Digraph('Characters of the Thrones', filename='thrones-graphviz')
576592
577593
for source, weighted_dict in G.items():
@@ -581,19 +597,18 @@ for source, weighted_dict in G.items():
581597

582598
```{code-cell} ipython3
583599
:cell_style: split
600+
:tags: [raises-exception]
584601
585602
gv.attr(rankdir='TB', size='12')
586603
gv
587604
```
588605

589606
```{code-cell} ipython3
607+
:tags: [raises-exception]
608+
590609
# save as svg
591610
# https://graphviz.readthedocs.io/en/stable/formats.html#formats
592611
593612
gv.format = 'svg'
594613
gv.render()
595614
```
596-
597-
```{code-cell} ipython3
598-
599-
```

notebooks/tps/pagerank-thrones/README-pagerank-thrones-nb.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ this radically different approach requires more care, but can then be drasticall
226226

227227
### data acquisition
228228

229+
```{code-cell} ipython3
230+
import pandas as pd
231+
```
232+
229233
```{code-cell} ipython3
230234
URL = "https://raw.githubusercontent.com/pupimvictor/NetworkOfThrones/master/stormofswords.csv"
231235
```
@@ -301,30 +305,39 @@ class PageRankWalker:
301305
if you've followed our interface, you can use the following code as-is
302306

303307
```{code-cell} ipython3
308+
:tags: [raises-exception]
309+
304310
# create a walker object from the graph obtained above
305311
306312
walker = PageRankWalker(G)
307313
```
308314

309315
```{code-cell} ipython3
310316
:cell_style: split
317+
:tags: [raises-exception]
311318
312319
STEPS = 1000
313320
314321
frequencies = walker.walk(STEPS)
315322
```
316323

317324
```{code-cell} ipython3
325+
:tags: [raises-exception]
326+
318327
# the sum of all values should be STEPS
319328
raincheck = sum(frequencies.values())
320329
raincheck == STEPS
321330
```
322331

323332
```{code-cell} ipython3
333+
:tags: [raises-exception]
334+
324335
raincheck, STEPS
325336
```
326337

327338
```{code-cell} ipython3
339+
:tags: [raises-exception]
340+
328341
# dicts are not so good at sorting
329342
# let's use a list instead
330343
@@ -394,13 +407,17 @@ def monte_carlo(url_or_filename, steps, damping=0.85):
394407
```
395408

396409
```{code-cell} ipython3
410+
:tags: [raises-exception]
411+
397412
# show top winners with a 1000-steps simu
398413
for _ in range(5):
399414
print(f"{40*'-'}")
400415
monte_carlo(URL, 1000)
401416
```
402417

403418
```{code-cell} ipython3
419+
:tags: [raises-exception]
420+
404421
# same with a tenfold simulation
405422
for _ in range(5):
406423
print(f"{40*'-'}")
@@ -436,6 +453,8 @@ from graphviz import Digraph
436453
```
437454

438455
```{code-cell} ipython3
456+
:tags: [raises-exception]
457+
439458
gv = Digraph('Characters of the Thrones', filename='thrones-graphviz')
440459
441460
for source, weighted_dict in G.items():
@@ -445,19 +464,18 @@ for source, weighted_dict in G.items():
445464

446465
```{code-cell} ipython3
447466
:cell_style: split
467+
:tags: [raises-exception]
448468
449469
gv.attr(rankdir='TB', size='12')
450470
gv
451471
```
452472

453473
```{code-cell} ipython3
474+
:tags: [raises-exception]
475+
454476
# save as svg
455477
# https://graphviz.readthedocs.io/en/stable/formats.html#formats
456478
457479
gv.format = 'svg'
458480
gv.render()
459481
```
460-
461-
```{code-cell} ipython3
462-
463-
```

0 commit comments

Comments
 (0)