8000 Merge branch 'rpy-parity' of https://github.com/plotly/plotly.r-docs … · johnbaums/plotly.r-docs@dfd7011 · GitHub
[go: up one dir, main page]

Skip to content

Commit dfd7011

Browse files
author
Kalpit Desai
committed
Merge branch 'rpy-parity' of https://github.com/plotly/plotly.r-docs into rpy-parity-dev
2 parents 4248f8e + 5c5851e commit dfd7011

File tree

2 files changed

+303
-291
lines changed

2 files changed

+303
-291
lines changed

r/2021-07-21-ml-knn.rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ We will train a [k-Nearest Neighbors (kNN)](https://parsnip.tidymodels.org/refer
1414

1515
### Display training and test splits
1616

17-
We get the synthetic data that form the shape of a moon. We then split it into a training and testing set. data that form the shape of a moon. We then split it into a training and testing set. Finally, we display the ground truth labels using [a scatter plot](https://plotly.com/r/line-and-scatter/).
17+
Using Tidymodels, we first generate synthetic data that form the shape of a moon. We then split it into a training and testing set. Finally, we display the ground truth labels using [a scatter plot](https://plotly.com/r/line-and-scatter/).
1818

1919
In the graph, we display all the negative labels as squares, and positive labels as circles. We differentiate the training and test set by adding a dot to the center of test data.
2020

@@ -23,7 +23,7 @@ library(tidyverse)
2323
library(tidymodels)
2424
library(plotly)
2525
26-
make_moons <- read.csv(file = "make_moons.csv")
26+
make_moons <- read.csv(file = "data/make_moons.csv")
2727
make_moons$y <- as.character(make_moons$y)
2828
set.seed(123)
2929
make_moons_split <- initial_split(make_moons, prop = 3/4)
@@ -49,7 +49,7 @@ fig
4949

5050
Now, we train the kNN model on the same training data displayed in the previous graph. Then, we predict the confidence score of the model for each of the data points in the test set. We will use shapes to denote the true labels, and the color will indicate the confidence of the model for assign that score.
5151

52-
Notice that `scatter` only requires one function call to plot both negative and positive labels, and can additionally set a continuous color scale based on the `yscore` output by our kNN model.
52+
Notice that `plot_ly` only requires one function call to plot both negative and positive labels, and can additionally set a continuous color scale based on the `yscore` output by our kNN model.
5353

5454
```{r}
5555
library(plotly)
@@ -206,7 +206,7 @@ fig
206206

207207
## Multi-class prediction confidence with [`Heatmap`](https://plotly.com/r/heatmaps/)
208208

209-
It is also possible to visualize the prediction confidence of the model using [heatmaps](https://plotly.com/r/heatmaps/). In this example, you can see how to compute how confident the model is about its prediction at every point in the 2D grid. Here, we define the confidence as the difference between the highest score and the score of the other classes summed, at a certain point.
209+
It is also possible to visualize the prediction confidence of the model using [heatmaps](https://plotly.com/r/heatmaps/). In this example, you can see how to compute how confident the model is about its prediction at every point in the 2D grid. Here, we define the confidence as the difference between the highest score and the sum of the score of the other classes, at a certain point.
210210

211211
```{r}
212212
library(pracma)

0 commit comments

Comments
 (0)
0