26
26
< meta name ="author " content ="Melissa Lee " />
27
27
28
28
29
- < meta name ="date " content ="2020-12-16 " />
29
+ < meta name ="date " content ="2021-01-12 " />
30
30
31
31
< meta name ="viewport " content ="width=device-width, initial-scale=1 " />
32
32
< meta name ="apple-mobile-web-app-capable " content ="yes " />
@@ -484,33 +484,33 @@ <h2><span class="header-section-number">7.3</span> Evaluating accuracy</h2>
484
484
< div class ="sourceCode " id ="cb207 "> < pre class ="sourceCode r "> < code class ="sourceCode r "> < span id ="cb207-1 "> < a href ="classification-continued.html#cb207-1 "> </ a > < span class ="kw "> glimpse</ span > (cancer_train)</ span > </ code > </ pre > </ div >
485
485
< pre > < code > ## Rows: 427
486
486
## Columns: 12
487
- ## $ ID <dbl> 842302, 842517, 84300903, 84348301, 84358402, 843786, 844359, 84458202, 84501 …
488
- ## $ Class <fct> M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, B, B, M, M, M, M, M, M, M, M, M, …
489
- ## $ Radius <dbl> 17.990, 20.570, 19.690, 11.420, 20.290, 12.450, 18.250, 13.710, 12.460, 16.02 …
490
- ## $ Texture <dbl> 10.38, 17.77, 21.25, 20.38, 14.34, 15.70, 19.98, 20.83, 24.04, 23.24, 17.89, …
491
- ## $ Perimeter <dbl> 122.80, 132.90, 130.00, 77.58, 135.10, 82.57, 119.60, 90.20, 83.97, 102.70, 1 …
492
- ## $ Area <dbl> 1001.0, 1326.0, 1203.0, 386.1, 1297.0, 477.1, 1040.0, 577.9, 475.9, 797.8, 78 …
493
- ## $ Smoothness <dbl> 0.11840, 0.08474, 0.10960, 0.14250, 0.10030, 0.12780, 0.09463, 0.11890, 0.118 …
494
- ## $ Compactness <dbl> 0.27760, 0.07864, 0.15990, 0.28390, 0.13280, 0.17000, 0.10900, 0.16450, 0.239 …
495
- ## $ Concavity <dbl> 0.30010, 0.08690, 0.19740, 0.24140, 0.19800, 0.15780, 0.11270, 0.09366, 0.227 …
496
- ## $ Concave_Points <dbl> 0.14710, 0.07017, 0.12790, 0.10520, 0.10430, 0.08089, 0.07400, 0.05985, 0.085 …
497
- ## $ Symmetry <dbl> 0.2419, 0.1812, 0.2069, 0.2597, 0.1809, 0.2087, 0.1794, 0.2196, 0.2030, 0.152 …
498
- ## $ Fractal_Dimension <dbl> 0.07871, 0.05667, 0.05999, 0.09744, 0.05883, 0.07613, 0.05742, 0.07451, 0.082 …</ code > </ pre >
487
+ ## $ ID <dbl> 842302, 842517, 84300903, 84348301, 84358402, 843786, 844359, 84458202…
488
+ ## $ Class <fct> M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, B, B, M, M, M, M, M, M, M…
489
+ ## $ Radius <dbl> 17.990, 20.570, 19.690, 11.420, 20.290, 12.450, 18.250, 13.710, 12.460…
490
+ ## $ Texture <dbl> 10.38, 17.77, 21.25, 20.38, 14.34, 15.70, 19.98, 20.83, 24.04, 23.24, …
491
+ ## $ Perimeter <dbl> 122.80, 132.90, 130.00, 77.58, 135.10, 82.57, 119.60, 90.20, 83.97, 10 …
492
+ ## $ Area <dbl> 1001.0, 1326.0, 1203.0, 386.1, 1297.0, 477.1, 1040.0, 577.9, 475.9, 79 …
493
+ ## $ Smoothness <dbl> 0.11840, 0.08474, 0.10960, 0.14250, 0.10030, 0.12780, 0.09463, 0.11890…
494
+ ## $ Compactness <dbl> 0.27760, 0.07864, 0.15990, 0.28390, 0.13280, 0.17000, 0.10900, 0.16450…
495
+ ## $ Concavity <dbl> 0.30010, 0.08690, 0.19740, 0.24140, 0.19800, 0.15780, 0.11270, 0.09366…
496
+ ## $ Concave_Points <dbl> 0.14710, 0.07017, 0.12790, 0.10520, 0.10430, 0.08089, 0.07400, 0.05985…
497
+ ## $ Symmetry <dbl> 0.2419, 0.1812, 0.2069, 0.2597, 0.1809, 0.2087, 0.1794, 0.2196, 0.2030…
498
+ ## $ Fractal_Dimension <dbl> 0.07871, 0.05667, 0.05999, 0.09744, 0.05883, 0.07613, 0.05742, 0.07451…</ code > </ pre >
499
499
< div class ="sourceCode " id ="cb209 "> < pre class ="sourceCode r "> < code class ="sourceCode r "> < span id ="cb209-1 "> < a href ="classification-continued.html#cb209-1 "> </ a > < span class ="kw "> glimpse</ span > (cancer_test)</ span > </ code > </ pre > </ div >
500
500
< pre > < code > ## Rows: 142
501
501
## Columns: 12
502
- ## $ ID <dbl> 844981, 84799002, 848406, 849014, 8510426, 8511133, 853401, 854002, 855167, 8 …
503
- ## $ Class <fct> M, M, M, M, B, M, M, M, M, M, M, B, B, M, M, M, B, M, M, B, B, B, M, M, B, B, …
504
- ## $ Radius <dbl> 13.000, 14.540, 14.680, 19.810, 13.540, 15.340, 18.630, 19.270, 13.440, 13.28 …
505
- ## $ Texture <dbl> 21.82, 27.54, 20.13, 22.15, 14.36, 14.26, 25.11, 26.47, 21.58, 20.28, 18.70, …
506
- ## $ Perimeter <dbl> 87.50, 96.73, 94.74, 130.00, 87.46, 102.50, 124.80, 127.90, 86.18, 87.32, 120 …
507
- ## $ Area <dbl> 519.8, 658.8, 684.5, 1260.0, 566.3, 704.4, 1088.0, 1162.0, 563.0, 545.2, 1033 …
508
- ## $ Smoothness <dbl> 0.12730, 0.11390, 0.09867, 0.09831, 0.09779, 0.10730, 0.10640, 0.09401, 0.081 …
509
- ## $ Compactness <dbl> 0.19320, 0.15950, 0.07200, 0.10270, 0.08129, 0.21350, 0.18870, 0.17190, 0.060 …
510
- ## $ Concavity <dbl> 0.18590, 0.16390, 0.07395, 0.14790, 0.06664, 0.20770, 0.23190, 0.16570, 0.031 …
511
- ## $ Concave_Points <dbl> 0.093530, 0.073640, 0.052590, 0.094980, 0.047810, 0.097560, 0.124400, 0.07593 …
512
- ## $ Symmetry <dbl> 0.2350, 0.2303, 0.1586, 0.1582, 0.1885, 0.2521, 0.2183, 0.1853, 0.1784, 0.197 …
513
- ## $ Fractal_Dimension <dbl> 0.07389, 0.07077, 0.05922, 0.05395, 0.05766, 0.07032, 0.06197, 0.06261, 0.055 …</ code > </ pre >
502
+ ## $ ID <dbl> 844981, 84799002, 848406, 849014, 8510426, 8511133, 853401, 854002, 85 …
503
+ ## $ Class <fct> M, M, M, M, B, M, M, M, M, M, M, B, B, M, M, M, B, M, M, B, B, B, M, M…
504
+ ## $ Radius <dbl> 13.000, 14.540, 14.680, 19.810, 13.540, 15.340, 18.630, 19.270, 13.440…
505
+ ## $ Texture <dbl> 21.82, 27.54, 20.13, 22.15, 14.36, 14.26, 25.11, 26.47, 21.58, 20.28, …
506
+ ## $ Perimeter <dbl> 87.50, 96.73, 94.74, 130.00, 87.46, 102.50, 124.80, 127.90, 86.18, 87.…
507
+ ## $ Area <dbl> 519.8, 658.8, 684.5, 1260.0, 566.3, 704.4, 1088.0, 1162.0, 563.0, 545.…
508
+ ## $ Smoothness <dbl> 0.12730, 0.11390, 0.09867, 0.09831, 0.09779, 0.10730, 0.10640, 0.09401…
509
+ ## $ Compactness <dbl> 0.19320, 0.15950, 0.07200, 0.10270, 0.08129, 0.21350, 0.18870, 0.17190…
510
+ ## $ Concavity <dbl> 0.18590, 0.16390, 0.07395, 0.14790, 0.06664, 0.20770, 0.23190, 0.16570…
511
+ ## $ Concave_Points <dbl> 0.093530, 0.073640, 0.052590, 0.094980, 0.047810, 0.097560, 0.124400, …
512
+ ## $ Symmetry <dbl> 0.2350, 0.2303, 0.1586, 0.1582, 0.1885, 0.2521, 0.2183, 0.1853, 0.1784…
513
+ ## $ Fractal_Dimension <dbl> 0.07389, 0.07077, 0.05922, 0.05395, 0.05766, 0.07032, 0.06197, 0.06261…</ code > </ pre >
514
514
< p > We can see from < code > glimpse</ code > in the code above that the training set contains 427
515
515
observations, while the test set contains 142 observations. This corresponds to
516
516
a train / test split of 75% / 25%, as desired.</ p >
@@ -545,17 +545,17 @@ <h2><span class="header-section-number">7.3</span> Evaluating accuracy</h2>
545
545
< span id ="cb212-9 "> < a href ="classification-continued.html#cb212-9 "> </ a > < span class ="st "> </ span > < span class ="kw "> fit</ span > (< span class ="dt "> data =</ span > cancer_train)</ span >
546
546
< span id ="cb212-10 "> < a href ="classification-continued.html#cb212-10 "> </ a > </ span >
547
547
< span id ="cb212-11 "> < a href ="classification-continued.html#cb212-11 "> </ a > knn_fit</ span > </ code > </ pre > </ div >
548
- < pre > < code > ## ══ Workflow [trained] ════════════════════════════════════════════════════════════════════════════════════
548
+ < pre > < code > ## ══ Workflow [trained] ═════════════════════════════════════════════════════════════════════════════
549
549
## Preprocessor: Recipe
550
550
## Model: nearest_neighbor()
551
551
##
552
- ## ── Preprocessor ──────────────────────────────────────────────────────────────────────────────────────────
552
+ ## ── Preprocessor ───────────────────────────────────────────────────────────────────────────────────
553
553
## 2 Recipe Steps
554
554
##
555
555
## ● step_scale()
556
556
## ● step_center()
557
557
##
558
- ## ── Model ─────────────────────────────────────────────────────────────────────────────────────────────────
558
+ ## ── Model ──────────────────────────────────────────────────────────────────────────────────────────
559
559
##
560
560
## Call:
561
561
## kknn::train.kknn(formula = formula, data = data, ks = ~3, kernel = ~"rectangular")
@@ -582,19 +582,20 @@ <h2><span class="header-section-number">7.3</span> Evaluating accuracy</h2>
582
582
< span id ="cb214-2 "> < a href ="classification-continued.html#cb214-2 "> </ a > < span class ="st "> </ span > < span class ="kw "> bind_cols</ span > (cancer_test)</ span >
583
583
< span id ="cb214-3 "> < a href ="classification-continued.html#cb214-3 "> </ a > cancer_test_predictions</ span > </ code > </ pre > </ div >
584
584
< pre > < code > ## # A tibble: 142 x 13
585
- ## .pred_class ID Class Radius Texture Perimeter Area Smoothness Compactness Concavity Concave_Points
586
- ## <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
587
- ## 1 M 8.45e5 M 13 21.8 87.5 520. 0.127 0.193 0.186 0.0935
588
- ## 2 M 8.48e7 M 14.5 27.5 96.7 659. 0.114 0.160 0.164 0.0736
589
- ## 3 B 8.48e5 M 14.7 20.1 94.7 684. 0.0987 0.072 0.0740 0.0526
590
- ## 4 M 8.49e5 M 19.8 22.2 130 1260 0.0983 0.103 0.148 0.0950
591
- ## 5 B 8.51e6 B 13.5 14.4 87.5 566. 0.0978 0.0813 0.0666 0.0478
592
- ## 6 M 8.51e6 M 15.3 14.3 102. 704. 0.107 0.214 0.208 0.0976
593
- ## 7 M 8.53e5 M 18.6 25.1 125. 1088 0.106 0.189 0.232 0.124
594
- ## 8 M 8.54e5 M 19.3 26.5 128. 1162 0.0940 0.172 0.166 0.0759
595
- ## 9 B 8.55e5 M 13.4 21.6 86.2 563 0.0816 0.0603 0.0311 0.0203
596
- ## 10 M 8.56e5 M 13.3 20.3 87.3 545. 0.104 0.144 0.0985 0.0616
597
- ## # … with 132 more rows, and 2 more variables: Symmetry <dbl>, Fractal_Dimension <dbl></ code > </ pre >
585
+ ## .pred_class ID Class Radius Texture Perimeter Area Smoothness Compactness Concavity
586
+ ## <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
587
+ ## 1 M 8.45e5 M 13 21.8 87.5 520. 0.127 0.193 0.186
588
+ ## 2 M 8.48e7 M 14.5 27.5 96.7 659. 0.114 0.160 0.164
589
+ ## 3 B 8.48e5 M 14.7 20.1 94.7 684. 0.0987 0.072 0.0740
590
+ ## 4 M 8.49e5 M 19.8 22.2 130 1260 0.0983 0.103 0.148
591
+ ## 5 B 8.51e6 B 13.5 14.4 87.5 566. 0.0978 0.0813 0.0666
592
+ ## 6 M 8.51e6 M 15.3 14.3 102. 704. 0.107 0.214 0.208
593
+ ## 7 M 8.53e5 M 18.6 25.1 125. 1088 0.106 0.189 0.232
594
+ ## 8 M 8.54e5 M 19.3 26.5 128. 1162 0.0940 0.172 0.166
595
+ ## 9 B 8.55e5 M 13.4 21.6 86.2 563 0.0816 0.0603 0.0311
596
+ ## 10 M 8.56e5 M 13.3 20.3 87.3 545. 0.104 0.144 0.0985
597
+ ## # … with 132 more rows, and 3 more variables: Concave_Points <dbl>, Symmetry <dbl>,
598
+ ## # Fractal_Dimension <dbl></ code > </ pre >
598
599
< p > < strong > 5. Compute the accuracy</ strong > </ p >
599
600
< p > Finally we can assess our classifier’s accuracy. To do this we use the < code > metrics</ code > function
600
601
from < code > tidymodels</ code > to get the statistics about the quality of our model, specifying
0 commit comments