@@ -16,6 +16,7 @@ kernelspec:
16
16
:tags: [remove-cell]
17
17
from chapter_preamble import *
18
18
from IPython.display import HTML
19
+ from IPython.display import Image
19
20
from sklearn.metrics.pairwise import euclidean_distances
20
21
import numpy as np
21
22
import plotly.express as px
@@ -281,6 +282,7 @@ perimeter and concavity variables. Recall that the default palette in `altair`
281
282
is colorblind-friendly, so we can stick with that here.
282
283
283
284
``` {code-cell} ipython3
285
+ :tags: ["remove-output"]
284
286
perim_concav = alt.Chart(cancer).mark_circle().encode(
285
287
x=alt.X("Perimeter").title("Perimeter (standardized)"),
286
288
y=alt.Y("Concavity").title("Concavity (standardized)"),
@@ -289,12 +291,16 @@ perim_concav = alt.Chart(cancer).mark_circle().encode(
289
291
perim_concav
290
292
```
291
293
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
293
300
:name: fig:05-scatter
294
- :figclass: caption-hack
295
301
296
302
Scatter plot of concavity versus perimeter colored by diagnosis label.
297
- ```
303
+ :::
298
304
299
305
+++
300
306
@@ -855,7 +861,11 @@ for neighbor_df in neighbor_df_list:
855
861
# tight layout
856
862
fig.update_layout(margin=dict(l=0, r=0, b=0, t=1), template="plotly_white")
857
863
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)
859
869
```
860
870
861
871
``` {figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
@@ -1432,6 +1442,7 @@ The new imbalanced data is shown in {numref}`fig:05-unbalanced`,
1432
1442
and we print the counts of the classes using the ` value_counts ` function.
1433
1443
1434
1444
``` {code-cell} ipython3
1445
+ :tags: ["remove-output"]
1435
1446
rare_cancer = pd.concat((
1436
1447
cancer[cancer["Class"] == "Benign"],
1437
1448
cancer[cancer["Class"] == "Malignant"].head(3)
@@ -1445,12 +1456,16 @@ rare_plot = alt.Chart(rare_cancer).mark_circle().encode(
1445
1456
rare_plot
1446
1457
```
1447
1458
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
1449
1465
:name: fig:05-unbalanced
1450
- :figclass: caption-hack
1451
1466
1452
1467
Imbalanced data.
1453
- ```
1468
+ :::
1454
1469
1455
1470
``` {code-cell} ipython3
1456
1471
rare_cancer["Class"].value_counts()
@@ -1947,16 +1962,15 @@ unscaled_plot + prediction_plot
1947
1962
```
1948
1963
1949
1964
``` {code-cell} ipython3
1950
- :tags: [remove-input ]
1965
+ :tags: [remove-cell ]
1951
1966
glue("fig:05-workflow-plot", (unscaled_plot + prediction_plot))
1952
1967
```
1953
1968
1954
- ``` { figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
1969
+ :::{glue : figure } fig:05-workflow-plot
1955
1970
:name: fig:05-workflow-plot
1956
- :figclass: caption-hack
1957
1971
1958
1972
Scatter plot of smoothness versus area where background color indicates the decision of the classifier.
1959
- ```
1973
+ :::
1960
1974
1961
1975
+++
1962
1976
@@ -1974,6 +1988,7 @@ found in {numref}`Chapter %s <move-to-your-own-machine>`. This will ensure that
1974
1988
and guidance that the worksheets provide will function as intended.
1975
1989
1976
1990
+++
1991
+
1977
1992
## References
1978
1993
1979
1994
``` {bibliography}
0 commit comments