Skip to content

Commit c485fd1

Browse files
Merge pull request #341 from UBC-DSCI/pdf-fixes
PDF fixes
2 parents d251a89 + 744c8f3 commit c485fd1

17 files changed

+226
-127
lines changed

source/classification1.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ kernelspec:
1616
:tags: [remove-cell]
1717
from chapter_preamble import *
1818
from IPython.display import HTML
19+
from IPython.display import Image
1920
from sklearn.metrics.pairwise import euclidean_distances
2021
import numpy as np
2122
import plotly.express as px
@@ -281,6 +282,7 @@ perimeter and concavity variables. Recall that the default palette in `altair`
281282
is colorblind-friendly, so we can stick with that here.
282283

283284
```{code-cell} ipython3
285+
:tags: ["remove-output"]
284286
perim_concav = alt.Chart(cancer).mark_circle().encode(
285287
x=alt.X("Perimeter").title("Perimeter (standardized)"),
286288
y=alt.Y("Concavity").title("Concavity (standardized)"),
@@ -289,12 +291,16 @@ perim_concav = alt.Chart(cancer).mark_circle().encode(
289291
perim_concav
290292
```
291293

292-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
294+
```{code-cell} ipython3
295+
:tags: ["remove-cell"]
296+
glue("fig:05-scatter", perim_concav)
297+
```
298+
299+
:::{glue:figure} fig:05-scatter
293300
:name: fig:05-scatter
294-
:figclass: caption-hack
295301

296302
Scatter plot of concavity versus perimeter colored by diagnosis label.
297-
```
303+
:::
298304

299305
+++
300306

@@ -855,7 +861,11 @@ for neighbor_df in neighbor_df_list:
855861
# tight layout
856862
fig.update_layout(margin=dict(l=0, r=0, b=0, t=1), template="plotly_white")
857863
858-
glue("fig:05-more", fig)
864+
# if HTML, use the plotly 3d image; if PDF, use static image
865+
if "BOOK_BUILD_TYPE" in os.environ and os.environ["BOOK_BUILD_TYPE"] == "PDF":
866+
glue("fig:05-more", Image("img/classification1/plot3d_knn_classification.png"))
867+
else:
868+
glue("fig:05-more", fig)
859869
```
860870

861871
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
@@ -1432,6 +1442,7 @@ The new imbalanced data is shown in {numref}`fig:05-unbalanced`,
14321442
and we print the counts of the classes using the `value_counts` function.
14331443

14341444
```{code-cell} ipython3
1445+
:tags: ["remove-output"]
14351446
rare_cancer = pd.concat((
14361447
cancer[cancer["Class"] == "Benign"],
14371448
cancer[cancer["Class"] == "Malignant"].head(3)
@@ -1445,12 +1456,16 @@ rare_plot = alt.Chart(rare_cancer).mark_circle().encode(
14451456
rare_plot
14461457
```
14471458

1448-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1459+
```{code-cell} ipython3
1460+
:tags: ["remove-cell"]
1461+
glue("fig:05-unbalanced", rare_plot)
1462+
```
1463+
1464+
:::{glue:figure} fig:05-unbalanced
14491465
:name: fig:05-unbalanced
1450-
:figclass: caption-hack
14511466

14521467
Imbalanced data.
1453-
```
1468+
:::
14541469

14551470
```{code-cell} ipython3
14561471
rare_cancer["Class"].value_counts()
@@ -1947,16 +1962,15 @@ unscaled_plot + prediction_plot
19471962
```
19481963

19491964
```{code-cell} ipython3
1950-
:tags: [remove-input]
1965+
:tags: [remove-cell]
19511966
glue("fig:05-workflow-plot", (unscaled_plot + prediction_plot))
19521967
```
19531968

1954-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1969+
:::{glue:figure} fig:05-workflow-plot
19551970
:name: fig:05-workflow-plot
1956-
:figclass: caption-hack
19571971

19581972
Scatter plot of smoothness versus area where background color indicates the decision of the classifier.
1959-
```
1973+
:::
19601974

19611975
+++
19621976

@@ -1974,6 +1988,7 @@ found in {numref}`Chapter %s <move-to-your-own-machine>`. This will ensure that
19741988
and guidance that the worksheets provide will function as intended.
19751989

19761990
+++
1991+
19771992
## References
19781993

19791994
```{bibliography}

source/classification2.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,20 +395,20 @@ the `random_state` argument that is available in many `pandas` and `scikit-learn
395395
functions. Those functions will then use your `Generator` to generate random numbers instead of
396396
`numpy`'s default generator. For example, we can reproduce our earlier example by using a `Generator`
397397
object with the `seed` value set to 1; we get the same lists of numbers once again.
398-
```{code}
398+
```python
399399
from numpy.random import Generator, PCG64
400400
rng = Generator(PCG64(seed=1))
401401
random_numbers1_third = nums_0_to_9.sample(n=10, random_state=rng).to_list()
402402
random_numbers1_third
403403
```
404-
```{code}
404+
```text
405405
array([2, 9, 6, 4, 0, 3, 1, 7, 8, 5])
406406
```
407-
```{code}
407+
```python
408408
random_numbers2_third = nums_0_to_9.sample(n=10, random_state=rng).to_list()
409409
random_numbers2_third
410410
```
411-
```{code}
411+
```text
412412
array([9, 5, 3, 0, 8, 4, 2, 1, 6, 7])
413413
```
414414
@@ -432,6 +432,7 @@ You will also notice that we set the random seed using the `np.random.seed` func
432432
as described in {numref}`randomseeds`.
433433

434434
```{code-cell} ipython3
435+
:tags: ["remove-output"]
435436
# load packages
436437
import altair as alt
437438
import pandas as pd
@@ -462,11 +463,18 @@ perim_concav = alt.Chart(cancer).mark_circle().encode(
462463
perim_concav
463464
```
464465

465-
```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
466+
```{code-cell} ipython3
467+
:tags: ["remove-cell"]
468+
glue("fig:06-precode", perim_concav)
469+
```
470+
471+
:::{glue:figure} fig:06-precode
466472
:name: fig:06-precode
467473

468474
Scatter plot of tumor cell concavity versus smoothness colored by diagnosis label.
469-
```
475+
:::
476+
477+
470478

471479
+++
472480

@@ -2205,10 +2213,10 @@ and guidance that the worksheets provide will function as intended.
22052213
text, it requires a bit more mathematical background than we require.
22062214

22072215

2208-
## References
2209-
22102216
+++
22112217

2218+
## References
2219+
22122220
```{bibliography}
22132221
:filter: docname in docnames
22142222
```

source/clustering.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,10 +1063,10 @@ and guidance that the worksheets provide will function as intended.
10631063
learning, it covers *principal components analysis (PCA)*, which is a very
10641064
popular technique for reducing the number of predictors in a data set.
10651065

1066-
## References
1067-
10681066
+++
10691067

1068+
## References
1069+
10701070
```{bibliography}
10711071
:filter: docname in docnames
10721072
```
Loading
Loading
Loading

0 commit comments

Comments
 (0)