From 15e84e93a2ac5da0ea54342bd89dbe0af55e5388 Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Tue, 12 Sep 2023 16:48:37 -0700 Subject: [PATCH 1/6] 3d figures work in classification 1 now --- .gitignore | 2 + Dockerfile | 3 + source/_config.yml | 2 + source/classification1.md | 14 ++--- source/img/classification1/fig05-more.html | 71 ---------------------- 5 files changed, 11 insertions(+), 81 deletions(-) delete mode 100755 source/img/classification1/fig05-more.html diff --git a/.gitignore b/.gitignore index d29738eb..8c7b766a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ source/*.py *.swp *.swo source/__pycache__ +.local/ +.viminfo diff --git a/Dockerfile b/Dockerfile index bfa4a498..0198cb3a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,9 @@ RUN pip install numpy jinja2 pandas"<2.1" altair">=5.1.1" "vegafusion[embed]" vl # TODO: remove this once scikit-learn 1.4.x or beyond releases and is incorporated into jupyter/scipy-notebook RUN pip install -U git+https://github.com/scikit-learn/scikit-learn.git@main +# install plotly for 3d figures +RUN pip install plotly + # disable warnings that pollute build logs; seems to be related to the update to python 3.11 # https://discourse.jupyter.org/t/debugger-warning-it-seems-that-frozen-modules-are-being-used-python-3-11-0/16544/12 ENV PYDEVD_DISABLE_FILE_VALIDATION=1 diff --git a/source/_config.yml b/source/_config.yml index 9468fb51..7c310080 100755 --- a/source/_config.yml +++ b/source/_config.yml @@ -78,6 +78,8 @@ sphinx: local_extensions: # A list of local extensions to load by sphinx specified by "name: path" items config: # key-value pairs to directly over-ride the Sphinx configuration bibtex_reference_style: author_year + html_js_files: + - https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js html_context: default_mode: light diff --git a/source/classification1.md b/source/classification1.md index 80e37e21..a0ca3cda 100755 --- a/source/classification1.md +++ b/source/classification1.md @@ -13,12 +13,12 @@ kernelspec: --- ```{code-cell} ipython3 -:tags: [remove-cell] - from chapter_preamble import * from IPython.display import HTML from sklearn.metrics.pairwise import euclidean_distances import numpy as np +import plotly.express as px +import plotly.graph_objects as go ``` (classification1)= @@ -781,7 +781,7 @@ for idx in min_5_idx: ``` ```{code-cell} ipython3 -:tags: [remove-cell] +:tags: [remove-input] fig = px.scatter_3d( perim_concav_with_new_point_df4, @@ -828,13 +828,7 @@ for neighbor_df in neighbor_df_list: # tight layout fig.update_layout(margin=dict(l=0, r=0, b=0, t=1), template="plotly_white") -plot(fig, filename="img/classification1/fig05-more.html", auto_open=False) -``` - -```{code-cell} ipython3 -:tags: [remove-input] - -display(HTML("img/classification1/fig05-more.html")) +glue("fig:05-more", fig) ``` ```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 diff --git a/source/img/classification1/fig05-more.html b/source/img/classification1/fig05-more.html deleted file mode 100755 index 19fd5958..00000000 --- a/source/img/classification1/fig05-more.html +++ /dev/null @@ -1,71 +0,0 @@ - - - -
-
- - \ No newline at end of file From 8e85a7abb7ad0cea7b6a78715495b9229dc39b15 Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Tue, 12 Sep 2023 16:51:00 -0700 Subject: [PATCH 2/6] same change to reg1 and reg2 --- source/regression1.md | 12 ++++-------- source/regression2.md | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/source/regression1.md b/source/regression1.md index e653d15f..d99f9ce4 100755 --- a/source/regression1.md +++ b/source/regression1.md @@ -20,6 +20,8 @@ kernelspec: from chapter_preamble import * from IPython.display import HTML +import plotly.express as px +import plotly.graph_objects as go ``` ## Overview @@ -1083,7 +1085,7 @@ time the predictions are a surface in 3D space, instead of a line in 2D space, a predictors instead of 1. ```{code-cell} ipython3 -:tags: [remove-cell] +:tags: [remove-input] # create a prediction pt grid xvals = np.linspace( @@ -1125,13 +1127,7 @@ fig.update_layout( template="plotly_white", ) -plot(fig, filename="img/regression1/fig07-knn-mult-viz.html", auto_open=False) -``` - -```{code-cell} ipython3 -:tags: [remove-input] - -display(HTML("img/regression1/fig07-knn-mult-viz.html")) +glue("fig:07-knn-mult-viz", fig) ``` ```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 diff --git a/source/regression2.md b/source/regression2.md index 7ce6c1db..77546db4 100755 --- a/source/regression2.md +++ b/source/regression2.md @@ -21,6 +21,8 @@ kernelspec: from chapter_preamble import * from IPython.display import HTML import numpy as np +import plotly.express as px +import plotly.graph_objects as go ``` ## Overview @@ -751,7 +753,7 @@ In the case of two predictors, we can plot the predictions made by our linear re shown in {numref}`fig:08-3DlinReg`. ```{code-cell} ipython3 -:tags: [remove-cell] +:tags: [remove-input] # create a prediction pt grid xvals = np.linspace( @@ -793,13 +795,7 @@ fig.update_layout( template="plotly_white", ) -plot(fig, filename="img/regression2/fig08-3DlinReg.html", auto_open=False) -``` - -```{code-cell} ipython3 -:tags: [remove-input] - -display(HTML("img/regression2/fig08-3DlinReg.html")) +glue("fig:08-3DlinReg", fig) ``` ```{figure} data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7 From 4ee765ea806bdd6da928e2807dad84964c602c2d Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Tue, 12 Sep 2023 16:59:43 -0700 Subject: [PATCH 3/6] removing imports in classification1 (had added for debugging); fix minor bug in reg1 --- source/classification1.md | 1 + source/regression1.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/source/classification1.md b/source/classification1.md index a0ca3cda..428143a7 100755 --- a/source/classification1.md +++ b/source/classification1.md @@ -13,6 +13,7 @@ kernelspec: --- ```{code-cell} ipython3 +:tags: [remove-cell] from chapter_preamble import * from IPython.display import HTML from sklearn.metrics.pairwise import euclidean_distances diff --git a/source/regression1.md b/source/regression1.md index d99f9ce4..936ffb8f 100755 --- a/source/regression1.md +++ b/source/regression1.md @@ -1098,7 +1098,7 @@ xygrid = np.array(np.meshgrid(xvals, yvals)).reshape(2, -1).T xygrid = pd.DataFrame(xygrid, columns=["sqft", "beds"]) # add prediction -knnPredGrid = sacr_pipeline_mult.predict(xygrid) +knnPredGrid = sacr_fit.predict(xygrid) fig = px.scatter_3d( sacramento_train, From 6591ff633a46ab5dd4f3e7b2238be2cd6de590b4 Mon Sep 17 00:00:00 2001 From: Trevor Campbell Date: Tue, 12 Sep 2023 17:00:30 -0700 Subject: [PATCH 4/6] removing old stored 3d viz --- .../img/regression1/fig07-knn-mult-viz.html | 71 ------------------- source/img/regression2/fig08-3DlinReg.html | 71 ------------------- 2 files changed, 142 deletions(-) delete mode 100755 source/img/regression1/fig07-knn-mult-viz.html delete mode 100755 source/img/regression2/fig08-3DlinReg.html diff --git a/source/img/regression1/fig07-knn-mult-viz.html b/source/img/regression1/fig07-knn-mult-viz.html deleted file mode 100755 index 06b1ec3a..00000000 --- a/source/img/regression1/fig07-knn-mult-viz.html +++ /dev/null @@ -1,71 +0,0 @@ - - - -
-
- - \ No newline at end of file diff --git a/source/img/regression2/fig08-3DlinReg.html b/source/img/regression2/fig08-3DlinReg.html deleted file mode 100755 index a8933675..00000000 --- a/source/img/regression2/fig08-3DlinReg.html +++ /dev/null @@ -1,71 +0,0 @@ - - - -
-
- - \ No newline at end of file From 30b6244cf6a2f8a5a254937f41b903e9861c5bf1 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 13 Sep 2023 18:20:44 +0000 Subject: [PATCH 5/6] update build_html.sh script with new docker image --- build_html.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_html.sh b/build_html.sh index 4cd27687..8809cd0e 100755 --- a/build_html.sh +++ b/build_html.sh @@ -1,2 +1,2 @@ chmod -R o+w source/ -docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20230831171718ddf538 /bin/bash -c "jupyter-book build source" +docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20230913180510589822 /bin/bash -c "jupyter-book build source" From 4e73d60eb38a91e0f6a73ba2590a5ae50c71bfa9 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 13 Sep 2023 18:20:45 +0000 Subject: [PATCH 6/6] update build_pdf.sh script with new docker image --- build_pdf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_pdf.sh b/build_pdf.sh index 619355ec..213c8b06 100755 --- a/build_pdf.sh +++ b/build_pdf.sh @@ -1,2 +1,2 @@ chmod -R o+w source/ -docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20230831171718ddf538 /bin/bash -c "export BOOK_BUILD_TYPE='PDF'; jupyter-book build source --builder pdflatex" +docker run --rm -v $(pwd):/home/jovyan ubcdsci/py-intro-to-ds:20230913180510589822 /bin/bash -c "export BOOK_BUILD_TYPE='PDF'; jupyter-book build source --builder pdflatex"