You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (knitr::is_latex_output()) 'latex' else 'pandoc'
13
13
})
14
+
reticulate::use_miniconda('r-reticulate')
14
15
```
15
16
16
17
## Overview
@@ -572,7 +573,7 @@ Based on $K=5$ nearest neighbors with these three predictors we would classify t
572
573
Figure \@ref(fig:05-more) shows what the data look like when we visualize them
573
574
as a 3-dimensional scatter with lines from the new observation to its five nearest neighbors.
574
575
575
-
```{r 05-more, echo = FALSE, message = FALSE, fig.cap = "3D scatter plot of the standardized symmetry, concavity, and perimeter variables. Note that in general we recommend against using 3D visualizations; here we show the data in 3D only to illustrate what higher dimensions and nearest neighbors look like, for learning purposes.", fig.retina=2, out.width="80%"}
576
+
```{r 05-more, echo = FALSE, message = FALSE, fig.cap = "3D scatter plot of the standardized symmetry, concavity, and perimeter variables. Note that in general we recommend against using 3D visualizations; here we show the data in 3D only to illustrate what higher dimensions and nearest neighbors look like, for learning purposes.", fig.retina=2, out.width="100%"}
576
577
attrs <- c("Perimeter", "Concavity", "Symmetry")
577
578
578
579
# create new scaled obs and get NNs
@@ -602,7 +603,7 @@ plot_3d <- scaled_cancer_3 |>
602
603
z = ~Symmetry,
603
604
color = ~Class,
604
605
opacity = 0.4,
605
-
size = 150,
606
+
size = 2,
606
607
colors = c("orange2", "steelblue2", "red"),
607
608
symbol = ~Class, symbols = c('circle','circle','diamond'))
608
609
@@ -641,6 +642,11 @@ plot_3d <- plot_3d %>%
641
642
if(!is_latex_output()){
642
643
plot_3d
643
644
} else {
645
+
# scene = list(camera = list(eye = list(x=2, y=2, z = 1.5)))
Copy file name to clipboardExpand all lines: clustering.Rmd
+15-5Lines changed: 15 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -254,7 +254,9 @@ In the first cluster from the example, there are `r nrow(clus1)` data points. Th
254
254
(`r paste("flipper_length_standardized =", round(mean(clus1$flipper_length_standardized),2))` and `r paste("bill_length_standardized =", round(mean(clus1$bill_length_standardized),2))`) highlighted
255
255
in Figure \@ref(fig:10-toy-example-clus1-center).
256
256
257
-
```{r 10-toy-example-clus1-center, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "Cluster 1 from the `penguin_data` data set example. Observations are in blue, with the cluster center highlighted in red."}
257
+
(ref:10-toy-example-clus1-center) Cluster 1 from the `penguin_data` data set example. Observations are in blue, with the cluster center highlighted in red.
These distances are denoted by lines in Figure \@ref(fig:10-toy-example-clus1-dists) for the first cluster of the penguin data example.
301
303
302
-
```{r 10-toy-example-clus1-dists, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 4.35, fig.cap = "Cluster 1 from the `penguin_data` data set example. Observations are in blue, with the cluster center highlighted in red. The distances from the observations to the cluster center are represented as black lines."}
304
+
(ref:10-toy-example-clus1-dists) Cluster 1 from the `penguin_data` data set example. Observations are in blue, with the cluster center highlighted in red. The distances from the observations to the cluster center are represented as black lines.
@@ -336,7 +340,9 @@ this means adding up all the squared distances for the 18 observations.
336
340
These distances are denoted by black lines in
337
341
Figure \@ref(fig:10-toy-example-all-clus-dists).
338
342
339
-
```{r 10-toy-example-all-clus-dists, echo = FALSE, warning = FALSE, fig.height = 4, fig.width = 5, fig.cap = "All clusters from the `penguin_data` data set example. Observations are in orange, blue, and yellow with the cluster center highlighted in red. The distances from the observations to each of the respective cluster centers are represented as black lines."}
343
+
(ref:10-toy-example-all-clus-dists) All clusters from the `penguin_data` data set example. Observations are in orange, blue, and yellow with the cluster center highlighted in red. The distances from the observations to each of the respective cluster centers are represented as black lines.
@@ -431,7 +437,9 @@ There each row corresponds to an iteration,
431
437
where the left column depicts the center update,
432
438
and the right column depicts the reassignment of data to clusters.
433
439
434
-
```{r 10-toy-kmeans-iter, echo = FALSE, warning = FALSE, fig.height = 16, fig.width = 8, fig.cap = "First four iterations of K-means clustering on the `penguin_data` example data set. Each row corresponds to an iteration, where the left column depicts the center update, and the right column depicts the reassignment of data to clusters. Cluster centers are indicated by larger points that are outlined in black."}
440
+
(ref:10-toy-kmeans-iter) First four iterations of K-means clustering on the `penguin_data` example data set. Each row corresponds to an iteration, where the left column depicts the center update, and the right column depicts the reassignment of data to clusters. Cluster centers are indicated by larger points that are outlined in black.
Figure \@ref(fig:10-toy-kmeans-bad-iter) shows what the iterations of K-means would look like with the unlucky random initialization shown in Figure \@ref(fig:10-toy-kmeans-bad-init).
559
567
560
-
```{r 10-toy-kmeans-bad-iter, echo = FALSE, warning = FALSE, fig.height = 20, fig.width = 8, fig.cap = "First five iterations of K-means clustering on the `penguin_data` example data set with a poor random initialization. Each row corresponds to an iteration, where the left column depicts the center update, and the right column depicts the reassignment of data to clusters. Cluster centers are indicated by larger points that are outlined in black."}
568
+
(ref:10-toy-kmeans-bad-iter) First five iterations of K-means clustering on the `penguin_data` example data set with a poor random initialization. Each row corresponds to an iteration, where the left column depicts the center update, and the right column depicts the reassignment of data to clusters. Cluster centers are indicated by larger points that are outlined in black.
Copy file name to clipboardExpand all lines: regression1.Rmd
+8-4Lines changed: 8 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,7 @@ library(knitr)
5
5
library(plotly)
6
6
7
7
knitr::opts_chunk$set(fig.align = "center")
8
+
reticulate::use_miniconda('r-reticulate')
8
9
```
9
10
10
11
## Overview
@@ -759,7 +760,7 @@ Figure \@ref(fig:07-knn-mult-viz) visualizes the model's predictions overlaid on
759
760
time the predictions are a surface in 3D space, instead of a line in 2D space, as we have 2
760
761
predictors instead of 1.
761
762
762
-
```{r 07-knn-mult-viz, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "KNN regression model’s predictions represented as a surface in 3D space overlaid on top of the data using three predictors (price, house size, and the number of bedrooms). Note that in general we recommend against using 3D visualizations; here we use a 3D visualization only to illustrate what the surface of predictions looks like for learning purposes.", out.width="80%"}
763
+
```{r 07-knn-mult-viz, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "KNN regression model’s predictions represented as a surface in 3D space overlaid on top of the data using three predictors (price, house size, and the number of bedrooms). Note that in general we recommend against using 3D visualizations; here we use a 3D visualization only to illustrate what the surface of predictions looks like for learning purposes.", out.width="100%"}
In the case of two predictors, we can plot the predictions made by our linear regression creates a *plane* of best fit, as
454
455
shown in Figure \@ref(fig:08-3DlinReg).
455
456
456
-
```{r 08-3DlinReg, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "Linear regression plane of best fit overlaid on top of the data (using price, house size, and number of bedrooms as predictors). Note that in general we recommend against using 3D visualizations; here we use a 3D visualization only to illustrate what the regression plane looks like for learning purposes.", out.width="80%"}
457
+
```{r 08-3DlinReg, echo = FALSE, message = FALSE, warning = FALSE, fig.cap = "Linear regression plane of best fit overlaid on top of the data (using price, house size, and number of bedrooms as predictors). Note that in general we recommend against using 3D visualizations; here we use a 3D visualization only to illustrate what the regression plane looks like for learning purposes.", out.width="100%"}
0 commit comments