8000 Getting 3D visualizations working again by trevorcampbell · Pull Request #240 · UBC-DSCI/introduction-to-datascience-python · GitHub
[go: up one dir, main page]

Skip to content

Getting 3D visualizations working again #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ source/*.py
*.swp
*.swo
source/__pycache__
.local/
.viminfo
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build_html.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion build_pdf.sh
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 2 additions & 0 deletions source/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 4 additions & 9 deletions source/classification1.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,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)=
Expand Down Expand Up @@ -781,7 +782,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,
Expand Down Expand Up @@ -828,13 +829,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
Expand Down
71 changes: 0 additions & 71 deletions source/img/classification1/fig05-more.html

This file was deleted.

71 changes: 0 additions & 71 deletions source/img/regression1/fig07-knn-mult-viz.html

This file was deleted.

71 changes: 0 additions & 71 deletions source/img/regression2/fig08-3DlinReg.html

This file was deleted.

14 changes: 5 additions & 9 deletions source/regression1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -1096,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,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions source/regression2.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
0