26
26
< meta name ="author " content ="Melissa Lee " />
27
27
28
28
29
- < meta name ="date " content ="2020-11-22 " />
29
+ < meta name ="date " content ="2020-11-24 " />
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 " />
@@ -453,33 +453,33 @@ <h2><span class="header-section-number">7.3</span> Evaluating accuracy</h2>
453
453
< div class ="sourceCode " id ="cb213 "> < pre class ="sourceCode r "> < code class ="sourceCode r "> < span id ="cb213-1 "> < a href ="classification-continued.html#cb213-1 "> </ a > < span class ="kw "> glimpse</ span > (cancer_train)</ span > </ code > </ pre > </ div >
454
454
< pre > < code > ## Rows: 427
455
455
## Columns: 12
456
- ## $ ID <dbl> 842302, 842517, 84300903, 84348301, 84358402, 84378 …
457
- ## $ Class <fct> M, M, M, M, M, M, M, M, M, M, M, M, M, M, M, B, B, …
458
- ## $ Radius <dbl> 17.990, 20.570, 19.690, 11.420, 20.290, 12.450, 18.…
459
- ## $ Texture <dbl> 10.38, 17.77, 21.25, 20.38, 14.34, 15.70, 19.98, 20…
460
- ## $ Perimeter <dbl> 122.80, 132.90, 130.00, 77.58, 135.10, 82.57, 119.6 …
461
- ## $ Area <dbl> 1001.0, 1326.0, 1203.0, 386.1, 1297.0, 477.1, 1040.…
462
- ## $ Smoothness <dbl> 0.11840, 0.08474, 0.10960, 0.14250, 0.10030, 0.1278 …
463
- ## $ Compactness <dbl> 0.27760, 0.07864, 0.15990, 0.28390, 0.13280, 0.1700 …
464
- ## $ Concavity <dbl> 0.30010, 0.08690, 0.19740, 0.24140, 0.19800, 0.1578 …
465
- ## $ Concave_Points <dbl> 0.14710 , 0.07017 , 0.12790 , 0.10520 , 0.10430 , 0.0808 …
466
- ## $ Symmetry <dbl> 0.2419, 0.1812, 0.2069, 0.2597, 0.1809, 0.2087, 0.1 …
467
- ## $ Fractal_Dimension <dbl> 0.07871, 0.05667, 0.05999, 0.09744, 0.05883, 0.0761 …</ code > </ pre >
456
+ ## $ ID <dbl> 842302, 842517, 84300903, 84348301, 84358402, 843786, 844359, 84458202, 84501001, 845 …
457
+ ## $ 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, M, M, M …
458
+ ## $ Radius <dbl> 17.990, 20.570, 19.690, 11.420, 20.290, 12.450, 18.250, 13.710, 12.460, 16.020, 15.78 …
459
+ ## $ Texture <dbl> 10.38, 17.77, 21.25, 20.38, 14.34, 15.70, 19.98, 20.83, 24.04, 23.24, 17.89, 24.80, 2 …
460
+ ## $ Perimeter <dbl> 122.80, 132.90, 130.00, 77.58, 135.10, 82.57, 119.60, 90.20, 83.97, 102.70, 103.60, 1 …
461
+ ## $ Area <dbl> 1001.0, 1326.0, 1203.0, 386.1, 1297.0, 477.1, 1040.0, 577.9, 475.9, 797.8, 781.0, 112 …
462
+ ## $ Smoothness <dbl> 0.11840, 0.08474, 0.10960, 0.14250, 0.10030, 0.12780, 0.09463, 0.11890, 0.11860, 0.08 …
463
+ ## $ Compactness <dbl> 0.27760, 0.07864, 0.15990, 0.28390, 0.13280, 0.17000, 0.10900, 0.16450, 0.23960, 0.06 …
464
+ ## $ Concavity <dbl> 0.30010, 0.08690, 0.19740, 0.24140, 0.19800, 0.15780, 0.11270, 0.09366, 0.22730, 0.03 …
465
+ ## $ Concave_Points <dbl> 0.147100 , 0.070170 , 0.127900 , 0.105200 , 0.104300 , 0.080890, 0.074000, 0.059850, 0.085 …
466
+ ## $ Symmetry <dbl> 0.2419, 0.1812, 0.2069, 0.2597, 0.1809, 0.2087, 0.1794, 0.2196, 0.2030, 0.1528, 0.184 …
467
+ ## $ Fractal_Dimension <dbl> 0.07871, 0.05667, 0.05999, 0.09744, 0.05883, 0.07613, 0.05742, 0.07451, 0.08243, 0.05 …</ code > </ pre >
468
468
< div class ="sourceCode " id ="cb215 "> < pre class ="sourceCode r "> < code class ="sourceCode r "> < span id ="cb215-1 "> < a href ="classification-continued.html#cb215-1 "> </ a > < span class ="kw "> glimpse</ span > (cancer_test)</ span > </ code > </ pre > </ div >
469
469
< pre > < code > ## Rows: 142
470
470
## Columns: 12
471
- ## $ ID <dbl> 844981, 84799002, 848406, 849014, 8510426, 8511133,…
472
- ## $ Class <fct> M, M, M, M, B, M, M, M, M, M, M, B, B, M, M, M, B, …
473
- ## $ Radius <dbl> 13.000, 14.540, 14.680, 19.810, 13.540, 15.340, 18.…
474
- ## $ Texture <dbl> 21.82, 27.54, 20.13, 22.15, 14.36, 14.26, 25.11, 26…
475
- ## $ Perimeter <dbl> 87.50, 96.73, 94.74, 130.00, 87.46, 102.50, 124.80,…
476
- ## $ Area <dbl> 519.8, 658.8, 684.5, 1260.0, 566.3, 704.4, 1088.0, …
477
- ## $ Smoothness <dbl> 0.12730, 0.11390, 0.09867, 0.09831, 0.09779, 0.1073 …
478
- ## $ Compactness <dbl> 0.19320, 0.15950, 0.07200, 0.10270, 0.08129, 0.2135 …
479
- ## $ Concavity <dbl> 0.18590, 0.16390, 0.07395, 0.14790, 0.06664, 0.2077 …
480
- ## $ Concave_Points <dbl> 0.093530, 0.073640, 0.052590, 0.094980, 0.047810, 0…
481
- ## $ Symmetry <dbl> 0.2350, 0.2303, 0.1586, 0.1582, 0.1885, 0.2521, 0.2 …
482
- ## $ Fractal_Dimension <dbl> 0.07389, 0.07077, 0.05922, 0.05395, 0.05766, 0.0703 …</ code > </ pre >
471
+ ## $ ID <dbl> 844981, 84799002, 848406, 849014, 8510426, 8511133, 853401, 854002, 855167, 856106, 8 …
472
+ ## $ 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, M, B, B …
473
+ ## $ Radius <dbl> 13.000, 14.540, 14.680, 19.810, 13.540, 15.340, 18.630, 19.270, 13.440, 13.280, 18.22 …
474
+ ## $ Texture <dbl> 21.82, 27.54, 20.13, 22.15, 14.36, 14.26, 25.11, 26.47, 21.58, 20.28, 18.70, 11.79, 1 …
475
+ ## $ Perimeter <dbl> 87.50, 96.73, 94.74, 130.00, 87.46, 102.50, 124.80, 127.90, 86.18, 87.32, 120.30, 54. …
476
+ ## $ Area <dbl> 519.8, 658.8, 684.5, 1260.0, 566.3, 704.4, 1088.0, 1162.0, 563.0, 545.2, 1033.0, 224. …
477
+ ## $ Smoothness <dbl> 0.12730, 0.11390, 0.09867, 0.09831, 0.09779, 0.10730, 0.10640, 0.09401, 0.08162, 0.10 …
478
+ ## $ Compactness <dbl> 0.19320, 0.15950, 0.07200, 0.10270, 0.08129, 0.21350, 0.18870, 0.17190, 0.06031, 0.14 …
479
+ ## $ Concavity <dbl> 0.18590, 0.16390, 0.07395, 0.14790, 0.06664, 0.20770, 0.23190, 0.16570, 0.03110, 0.09 …
480
+ ## $ Concave_Points <dbl> 0.093530, 0.073640, 0.052590, 0.094980, 0.047810, 0.097560, 0.124400, 0.075930, 0.020 …
481
+ ## $ Symmetry <dbl> 0.2350, 0.2303, 0.1586, 0.1582, 0.1885, 0.2521, 0.2183, 0.1853, 0.1784, 0.1974, 0.209 …
482
+ ## $ Fractal_Dimension <dbl> 0.07389, 0.07077, 0.05922, 0.05395, 0.05766, 0.07032, 0.06197, 0.06261, 0.05587, 0.06 …</ code > </ pre >
483
483
< p > We can see from < code > glimpse</ code > in the code above that the training set contains 427
484
484
observations, while the test set contains 142 observations. This corresponds to
485
485
a train / test split of 75% / 25%, as desired.</ p >
@@ -514,17 +514,17 @@ <h2><span class="header-section-number">7.3</span> Evaluating accuracy</h2>
514
514
< span id ="cb218-9 "> < a href ="classification-continued.html#cb218-9 "> </ a > < span class ="st "> </ span > < span class ="kw "> fit</ span > (< span class ="dt "> data =</ span > cancer_train)</ span >
515
515
< span id ="cb218-10 "> < a href ="classification-continued.html#cb218-10 "> </ a > </ span >
516
516
< span id ="cb218-11 "> < a href ="classification-continued.html#cb218-11 "> </ a > knn_fit</ span > </ code > </ pre > </ div >
517
- < pre > < code > ## ══ Workflow [trained] ══════════════════════════════════════════════════════════
517
+ < pre > < code > ## ══ Workflow [trained] ════════════════════════════════════════════════════════════════════════════════════════════
518
518
## Preprocessor: Recipe
519
519
## Model: nearest_neighbor()
520
520
##
521
- ## ── Preprocessor ────────────────────────────────────────────────────────────────
521
+ ## ── Preprocessor ──────────────────────────────────────────────────────────────────────────────────────────────────
522
522
## 2 Recipe Steps
523
523
##
524
524
## ● step_scale()
525
525
## ● step_center()
526
526
##
527
- ## ── Model ───────────────────────────────────────────────────────────────────────
527
+ ## ── Model ─────────────────────────────────────────────────────────────────────────────────────────────────────────
528
528
##
529
529
## Call:
530
530
## kknn::train.kknn(formula = formula, data = data, ks = ~3, kernel = ~"rectangular")
@@ -551,16 +551,15 @@ <h2><span class="header-section-number">7.3</span> Evaluating accuracy</h2>
551
551
< span id ="cb220-2 "> < a href ="classification-continued.html#cb220-2 "> </ a > < span class ="st "> </ span > < span class ="kw "> bind_cols</ span > (cancer_test)</ span >
552
552
< span id ="cb220-3 "> < a href ="classification-continued.html#cb220-3 "> </ a > < span class ="kw "> head</ span > (cancer_test_predictions)</ span > </ code > </ pre > </ div >
553
553
< pre > < code > ## # A tibble: 6 x 13
554
- ## .pred_class ID Class Radius Texture Perimeter Area Smoothness Compactness
555
- ## <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
556
- ## 1 M 8.45e5 M 13 21.8 87.5 520. 0.127 0.193
557
- ## 2 M 8.48e7 M 14.5 27.5 96.7 659. 0.114 0.160
558
- ## 3 B 8.48e5 M 14.7 20.1 94.7 684. 0.0987 0.072
559
- ## 4 M 8.49e5 M 19.8 22.2 130 1260 0.0983 0.103
560
- ## 5 B 8.51e6 B 13.5 14.4 87.5 566. 0.0978 0.0813
561
- ## 6 M 8.51e6 M 15.3 14.3 102. 704. 0.107 0.214
562
- ## # … with 4 more variables: Concavity <dbl>, Concave_Points <dbl>,
563
- ## # Symmetry <dbl>, Fractal_Dimension <dbl></ code > </ pre >
554
+ ## .pred_class ID Class Radius Texture Perimeter Area Smoothness Compactness Concavity Concave_Points Symmetry
555
+ ## <fct> <dbl> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
556
+ ## 1 M 8.45e5 M 13 21.8 87.5 520. 0.127 0.193 0.186 0.0935 0.235
557
+ ## 2 M 8.48e7 M 14.5 27.5 96.7 659. 0.114 0.160 0.164 0.0736 0.230
558
+ ## 3 B 8.48e5 M 14.7 20.1 94.7 684. 0.0987 0.072 0.0740 0.0526 0.159
559
+ ## 4 M 8.49e5 M 19.8 22.2 130 1260 0.0983 0.103 0.148 0.0950 0.158
560
+ ## 5 B 8.51e6 B 13.5 14.4 87.5 566. 0.0978 0.0813 0.0666 0.0478 0.188
561
+ ## 6 M 8.51e6 M 15.3 14.3 102. 704. 0.107 0.214 0.208 0.0976 0.252
562
+ ## # … with 1 more variable: Fractal_Dimension <dbl></ code > </ pre >
564
563
< p > < strong > 5. Compute the accuracy</ strong > </ p >
565
564
< p > Finally we can assess our classifier’s accuracy. To do this we use the < code > metrics</ code > function
566
565
from < code > tidymodels</ code > to get the statistics about the quality of our model, specifying
0 commit comments