data <- read.csv("~/data.csv")
head(data)
##         id diagnosis radius_mean texture_mean perimeter_mean area_mean
## 1   842302         M       17.99        10.38         122.80    1001.0
## 2   842517         M       20.57        17.77         132.90    1326.0
## 3 84300903         M       19.69        21.25         130.00    1203.0
## 4 84348301         M       11.42        20.38          77.58     386.1
## 5 84358402         M       20.29        14.34         135.10    1297.0
## 6   843786         M       12.45        15.70          82.57     477.1
##   smoothness_mean compactness_mean concavity_mean concave.points_mean
## 1         0.11840          0.27760         0.3001             0.14710
## 2         0.08474          0.07864         0.0869             0.07017
## 3         0.10960          0.15990         0.1974             0.12790
## 4         0.14250          0.28390         0.2414             0.10520
## 5         0.10030          0.13280         0.1980             0.10430
## 6         0.12780          0.17000         0.1578             0.08089
##   symmetry_mean fractal_dimension_mean radius_se texture_se perimeter_se
## 1        0.2419                0.07871    1.0950     0.9053        8.589
## 2        0.1812                0.05667    0.5435     0.7339        3.398
## 3        0.2069                0.05999    0.7456     0.7869        4.585
## 4        0.2597                0.09744    0.4956     1.1560        3.445
## 5        0.1809                0.05883    0.7572     0.7813        5.438
## 6        0.2087                0.07613    0.3345     0.8902        2.217
##   area_se smoothness_se compactness_se concavity_se concave.points_se
## 1  153.40      0.006399        0.04904      0.05373           0.01587
## 2   74.08      0.005225        0.01308      0.01860           0.01340
## 3   94.03      0.006150        0.04006      0.03832           0.02058
## 4   27.23      0.009110        0.07458      0.05661           0.01867
## 5   94.44      0.011490        0.02461      0.05688           0.01885
## 6   27.19      0.007510        0.03345      0.03672           0.01137
##   symmetry_se fractal_dimension_se radius_worst texture_worst perimeter_worst
## 1     0.03003             0.006193        25.38         17.33          184.60
## 2     0.01389             0.003532        24.99         23.41          158.80
## 3     0.02250             0.004571        23.57         25.53          152.50
## 4     0.05963             0.009208        14.91         26.50           98.87
## 5     0.01756             0.005115        22.54         16.67          152.20
## 6     0.02165             0.005082        15.47         23.75          103.40
##   area_worst smoothness_worst compactness_worst concavity_worst
## 1     2019.0           0.1622            0.6656          0.7119
## 2     1956.0           0.1238            0.1866          0.2416
## 3     1709.0           0.1444            0.4245          0.4504
## 4      567.7           0.2098            0.8663          0.6869
## 5     1575.0           0.1374            0.2050          0.4000
## 6      741.6           0.1791            0.5249          0.5355
##   concave.points_worst symmetry_worst fractal_dimension_worst  X
## 1               0.2654         0.4601                 0.11890 NA
## 2               0.1860         0.2750                 0.08902 NA
## 3               0.2430         0.3613                 0.08758 NA
## 4               0.2575         0.6638                 0.17300 NA
## 5               0.1625         0.2364                 0.07678 NA
## 6               0.1741         0.3985                 0.12440 NA
summary(data)
##        id             diagnosis          radius_mean      texture_mean  
##  Min.   :     8670   Length:569         Min.   : 6.981   Min.   : 9.71  
##  1st Qu.:   869218   Class :character   1st Qu.:11.700   1st Qu.:16.17  
##  Median :   906024   Mode  :character   Median :13.370   Median :18.84  
##  Mean   : 30371831                      Mean   :14.127   Mean   :19.29  
##  3rd Qu.:  8813129                      3rd Qu.:15.780   3rd Qu.:21.80  
##  Max.   :911320502                      Max.   :28.110   Max.   :39.28  
##  perimeter_mean     area_mean      smoothness_mean   compactness_mean 
##  Min.   : 43.79   Min.   : 143.5   Min.   :0.05263   Min.   :0.01938  
##  1st Qu.: 75.17   1st Qu.: 420.3   1st Qu.:0.08637   1st Qu.:0.06492  
##  Median : 86.24   Median : 551.1   Median :0.09587   Median :0.09263  
##  Mean   : 91.97   Mean   : 654.9   Mean   :0.09636   Mean   :0.10434  
##  3rd Qu.:104.10   3rd Qu.: 782.7   3rd Qu.:0.10530   3rd Qu.:0.13040  
##  Max.   :188.50   Max.   :2501.0   Max.   :0.16340   Max.   :0.34540  
##  concavity_mean    concave.points_mean symmetry_mean    fractal_dimension_mean
##  Min.   :0.00000   Min.   :0.00000     Min.   :0.1060   Min.   :0.04996       
##  1st Qu.:0.02956   1st Qu.:0.02031     1st Qu.:0.1619   1st Qu.:0.05770       
##  Median :0.06154   Median :0.03350     Median :0.1792   Median :0.06154       
##  Mean   :0.08880   Mean   :0.04892     Mean   :0.1812   Mean   :0.06280       
##  3rd Qu.:0.13070   3rd Qu.:0.07400     3rd Qu.:0.1957   3rd Qu.:0.06612       
##  Max.   :0.42680   Max.   :0.20120     Max.   :0.3040   Max.   :0.09744       
##    radius_se        texture_se      perimeter_se       area_se       
##  Min.   :0.1115   Min.   :0.3602   Min.   : 0.757   Min.   :  6.802  
##  1st Qu.:0.2324   1st Qu.:0.8339   1st Qu.: 1.606   1st Qu.: 17.850  
##  Median :0.3242   Median :1.1080   Median : 2.287   Median : 24.530  
##  Mean   :0.4052   Mean   :1.2169   Mean   : 2.866   Mean   : 40.337  
##  3rd Qu.:0.4789   3rd Qu.:1.4740   3rd Qu.: 3.357   3rd Qu.: 45.190  
##  Max.   :2.8730   Max.   :4.8850   Max.   :21.980   Max.   :542.200  
##  smoothness_se      compactness_se      concavity_se     concave.points_se 
##  Min.   :0.001713   Min.   :0.002252   Min.   :0.00000   Min.   :0.000000  
##  1st Qu.:0.005169   1st Qu.:0.013080   1st Qu.:0.01509   1st Qu.:0.007638  
##  Median :0.006380   Median :0.020450   Median :0.02589   Median :0.010930  
##  Mean   :0.007041   Mean   :0.025478   Mean   :0.03189   Mean   :0.011796  
##  3rd Qu.:0.008146   3rd Qu.:0.032450   3rd Qu.:0.04205   3rd Qu.:0.014710  
##  Max.   :0.031130   Max.   :0.135400   Max.   :0.39600   Max.   :0.052790  
##   symmetry_se       fractal_dimension_se  radius_worst   texture_worst  
##  Min.   :0.007882   Min.   :0.0008948    Min.   : 7.93   Min.   :12.02  
##  1st Qu.:0.015160   1st Qu.:0.0022480    1st Qu.:13.01   1st Qu.:21.08  
##  Median :0.018730   Median :0.0031870    Median :14.97   Median :25.41  
##  Mean   :0.020542   Mean   :0.0037949    Mean   :16.27   Mean   :25.68  
##  3rd Qu.:0.023480   3rd Qu.:0.0045580    3rd Qu.:18.79   3rd Qu.:29.72  
##  Max.   :0.078950   Max.   :0.0298400    Max.   :36.04   Max.   :49.54  
##  perimeter_worst    area_worst     smoothness_worst  compactness_worst
##  Min.   : 50.41   Min.   : 185.2   Min.   :0.07117   Min.   :0.02729  
##  1st Qu.: 84.11   1st Qu.: 515.3   1st Qu.:0.11660   1st Qu.:0.14720  
##  Median : 97.66   Median : 686.5   Median :0.13130   Median :0.21190  
##  Mean   :107.26   Mean   : 880.6   Mean   :0.13237   Mean   :0.25427  
##  3rd Qu.:125.40   3rd Qu.:1084.0   3rd Qu.:0.14600   3rd Qu.:0.33910  
##  Max.   :251.20   Max.   :4254.0   Max.   :0.22260   Max.   :1.05800  
##  concavity_worst  concave.points_worst symmetry_worst   fractal_dimension_worst
##  Min.   :0.0000   Min.   :0.00000      Min.   :0.1565   Min.   :0.05504        
##  1st Qu.:0.1145   1st Qu.:0.06493      1st Qu.:0.2504   1st Qu.:0.07146        
##  Median :0.2267   Median :0.09993      Median :0.2822   Median :0.08004        
##  Mean   :0.2722   Mean   :0.11461      Mean   :0.2901   Mean   :0.08395        
##  3rd Qu.:0.3829   3rd Qu.:0.16140      3rd Qu.:0.3179   3rd Qu.:0.09208        
##  Max.   :1.2520   Max.   :0.29100      Max.   :0.6638   Max.   :0.20750        
##     X          
##  Mode:logical  
##  NA's:569      
##                
##                
##                
## 
data <- data[,-1]

Boxplotlar

par(mfrow=c(2,5)) 
for(i in 2:31) {
   boxplot(data[,i], main=names(data)[i])
 }

par(mfrow=c(2,5)) 
for(i in 2:31) {
   plot(density(data[,i]), main=names(data)[i])
 }

 #par(mfrow=c(1,1))
library(corrplot)
## corrplot 0.92 loaded
# Korelasyonun hesaplanması
correlations <- cor(data[,3:32]) # Korelasyon grafiÄŸi oluÅŸturma 
corrplot(correlations, method="circle")

library(caret)
## Loading required package: ggplot2
## Loading required package: lattice
library(randomForest)
## randomForest 4.7-1.1
## Type rfNews() to see new features/changes/bug fixes.
## 
## Attaching package: 'randomForest'
## The following object is masked from 'package:ggplot2':
## 
##     margin
control <- trainControl(method="repeatedcv", number=10, repeats=3)
data$diagnosis <- as.factor(data$diagnosis)
# Check for missing values in each column
missing_summary <- sapply(data, function(x) sum(is.na(x)))
# Remove rows with any missing values
data_clean <- na.omit(data)
data_clean <- data[, !names(data) %in% c("X")]

DoÄŸruluÄŸu geliÅŸtirme

set.seed(7)
split <- createDataPartition(y=data_clean$diagnosis, p=0.7, list=FALSE)
trainData <- data_clean[split,]
testData <- data_clean[-split,]
set.seed(7)
metric <- "Accuracy"
tunegrid <- expand.grid(.mtry=c(2:5))
rf_gridsearch <- train(diagnosis~., data=trainData, method="rf", metric=metric, tuneGrid=tunegrid, trControl=control)
bestmtry = rf_gridsearch$bestTune
print(rf_gridsearch)
## Random Forest 
## 
## 399 samples
##  30 predictor
##   2 classes: 'B', 'M' 
## 
## No pre-processing
## Resampling: Cross-Validated (10 fold, repeated 3 times) 
## Summary of sample sizes: 360, 359, 359, 359, 359, 359, ... 
## Resampling results across tuning parameters:
## 
##   mtry  Accuracy   Kappa    
##   2     0.9524145  0.8972375
##   3     0.9499145  0.8921589
##   4     0.9524145  0.8976500
##   5     0.9507479  0.8944420
## 
## Accuracy was used to select the optimal model using the largest value.
## The final value used for the model was mtry = 4.
plot(rf_gridsearch)

print(bestmtry$mtry)
## [1] 4
# Load necessary libraries
library(caret)
library(randomForest)

# Initialize an empty list to store models
modellist <- list()

# Set seed for reproducibility
set.seed(7)

# Loop over different numbers of trees and mtry values
for (ntree in c(500, 1500, 2500, 3500, 4500)) {
  for (mtry in c(2, 4, 6, 8, 10)) {
    
    # Define the tuning grid for mtry
    tunegrid <- expand.grid(.mtry = mtry)
    
    # Train the model with the specified parameters
    fit <- train(diagnosis ~ ., 
                 data = trainData, 
                 method = "rf", 
                 metric = metric, 
                 tuneGrid = tunegrid, 
                 trControl = control, 
                 ntree = ntree)
    
    # Use a unique key combining ntree and mtry to store the model
    key <- paste("ntree", ntree, "mtry", mtry, sep = "_")
    modellist[[key]] <- fit
  }
}

# Compare results using resamples
results <- resamples(modellist)

# Summary of results
summary(results)
## 
## Call:
## summary.resamples(object = results)
## 
## Models: ntree_500_mtry_2, ntree_500_mtry_4, ntree_500_mtry_6, ntree_500_mtry_8, ntree_500_mtry_10, ntree_1500_mtry_2, ntree_1500_mtry_4, ntree_1500_mtry_6, ntree_1500_mtry_8, ntree_1500_mtry_10, ntree_2500_mtry_2, ntree_2500_mtry_4, ntree_2500_mtry_6, ntree_2500_mtry_8, ntree_2500_mtry_10, ntree_3500_mtry_2, ntree_3500_mtry_4, ntree_3500_mtry_6, ntree_3500_mtry_8, ntree_3500_mtry_10, ntree_4500_mtry_2, ntree_4500_mtry_4, ntree_4500_mtry_6, ntree_4500_mtry_8, ntree_4500_mtry_10 
## Number of resamples: 30 
## 
## Accuracy 
##                         Min.   1st Qu.    Median      Mean   3rd Qu.  Max. NA's
## ntree_500_mtry_2   0.8750000 0.9250000 0.9500000 0.9532479 0.9937500 1.000    0
## ntree_500_mtry_4   0.8500000 0.9309295 0.9500000 0.9489957 0.9750000 1.000    0
## ntree_500_mtry_6   0.8750000 0.9250000 0.9487179 0.9465171 0.9750000 1.000    0
## ntree_500_mtry_8   0.8750000 0.9250000 0.9500000 0.9482479 0.9750000 1.000    0
## ntree_500_mtry_10  0.9000000 0.9250000 0.9500000 0.9498932 0.9750000 1.000    0
## ntree_1500_mtry_2  0.8500000 0.9309295 0.9743590 0.9549145 0.9750000 1.000    0
## ntree_1500_mtry_4  0.9000000 0.9250000 0.9500000 0.9473932 0.9748397 0.975    0
## ntree_1500_mtry_6  0.8500000 0.9490385 0.9500000 0.9524145 0.9750000 1.000    0
## ntree_1500_mtry_8  0.8500000 0.9312500 0.9500000 0.9507265 0.9750000 1.000    0
## ntree_1500_mtry_10 0.9000000 0.9250000 0.9500000 0.9523291 0.9750000 1.000    0
## ntree_2500_mtry_2  0.8750000 0.9312500 0.9500000 0.9523932 0.9750000 1.000    0
## ntree_2500_mtry_4  0.8500000 0.9250000 0.9500000 0.9498718 0.9750000 1.000    0
## ntree_2500_mtry_6  0.8974359 0.9250000 0.9500000 0.9514744 0.9750000 1.000    0
## ntree_2500_mtry_8  0.9000000 0.9250000 0.9500000 0.9490598 0.9750000 1.000    0
## ntree_2500_mtry_10 0.8250000 0.9312500 0.9500000 0.9506624 0.9750000 1.000    0
## ntree_3500_mtry_2  0.8750000 0.9309295 0.9500000 0.9557692 0.9750000 1.000    0
## ntree_3500_mtry_4  0.8750000 0.9250000 0.9500000 0.9499359 0.9750000 1.000    0
## ntree_3500_mtry_6  0.8500000 0.9250000 0.9500000 0.9482479 0.9750000 1.000    0
## ntree_3500_mtry_8  0.8500000 0.9250000 0.9500000 0.9491239 0.9750000 1.000    0
## ntree_3500_mtry_10 0.8750000 0.9250000 0.9500000 0.9507906 0.9750000 1.000    0
## ntree_4500_mtry_2  0.8750000 0.9250000 0.9500000 0.9516239 0.9750000 1.000    0
## ntree_4500_mtry_4  0.8750000 0.9250000 0.9500000 0.9499145 0.9750000 1.000    0
## ntree_4500_mtry_6  0.8974359 0.9250000 0.9500000 0.9507051 0.9750000 1.000    0
## ntree_4500_mtry_8  0.8750000 0.9250000 0.9500000 0.9506624 0.9750000 1.000    0
## ntree_4500_mtry_10 0.8750000 0.9250000 0.9500000 0.9507479 0.9750000 1.000    0
## 
## Kappa 
##                         Min.   1st Qu.    Median      Mean   3rd Qu.      Max.
## ntree_500_mtry_2   0.7297297 0.8378378 0.8918721 0.8989958 0.9868421 1.0000000
## ntree_500_mtry_4   0.6800000 0.8496173 0.8933333 0.8904725 0.9459459 1.0000000
## ntree_500_mtry_6   0.7222222 0.8378378 0.8867636 0.8845775 0.9473684 1.0000000
## ntree_500_mtry_8   0.7222222 0.8389047 0.8933333 0.8888189 0.9459459 1.0000000
## ntree_500_mtry_10  0.7746479 0.8378378 0.8947186 0.8922721 0.9470128 1.0000000
## ntree_1500_mtry_2  0.6619718 0.8537218 0.9433962 0.9024974 0.9459459 1.0000000
## ntree_1500_mtry_4  0.7808219 0.8421053 0.8918721 0.8870054 0.9457464 0.9473684
## ntree_1500_mtry_6  0.6883117 0.8890313 0.8933333 0.8979058 0.9459459 1.0000000
## ntree_1500_mtry_8  0.6800000 0.8541817 0.8933333 0.8943531 0.9459459 1.0000000
## ntree_1500_mtry_10 0.7808219 0.8421053 0.8933333 0.8974950 0.9459459 1.0000000
## ntree_2500_mtry_2  0.7297297 0.8541817 0.8933333 0.8978135 0.9459459 1.0000000
## ntree_2500_mtry_4  0.6800000 0.8378378 0.8933333 0.8925057 0.9470128 1.0000000
## ntree_2500_mtry_6  0.7771429 0.8389047 0.8933333 0.8960357 0.9459459 1.0000000
## ntree_2500_mtry_8  0.7808219 0.8421053 0.8911889 0.8905659 0.9459459 1.0000000
## ntree_2500_mtry_10 0.6315789 0.8541817 0.8933333 0.8944633 0.9459459 1.0000000
## ntree_3500_mtry_2  0.7222222 0.8537218 0.8933333 0.9046287 0.9459459 1.0000000
## ntree_3500_mtry_4  0.7297297 0.8389047 0.8933333 0.8924848 0.9459459 1.0000000
## ntree_3500_mtry_6  0.6619718 0.8378378 0.8933333 0.8883906 0.9459459 1.0000000
## ntree_3500_mtry_8  0.6800000 0.8431174 0.8933333 0.8909390 0.9459459 1.0000000
## ntree_3500_mtry_10 0.7435897 0.8389047 0.8933333 0.8949027 0.9459459 1.0000000
## ntree_4500_mtry_2  0.7297297 0.8389047 0.8918721 0.8953407 0.9473684 1.0000000
## ntree_4500_mtry_4  0.7368421 0.8421053 0.8918721 0.8923278 0.9459459 1.0000000
## ntree_4500_mtry_6  0.7839335 0.8421053 0.8904110 0.8944626 0.9459459 1.0000000
## ntree_4500_mtry_8  0.7368421 0.8431174 0.8933333 0.8944207 0.9459459 1.0000000
## ntree_4500_mtry_10 0.7297297 0.8389047 0.8933333 0.8943792 0.9459459 1.0000000
##                    NA's
## ntree_500_mtry_2      0
## ntree_500_mtry_4      0
## ntree_500_mtry_6      0
## ntree_500_mtry_8      0
## ntree_500_mtry_10     0
## ntree_1500_mtry_2     0
## ntree_1500_mtry_4     0
## ntree_1500_mtry_6     0
## ntree_1500_mtry_8     0
## ntree_1500_mtry_10    0
## ntree_2500_mtry_2     0
## ntree_2500_mtry_4     0
## ntree_2500_mtry_6     0
## ntree_2500_mtry_8     0
## ntree_2500_mtry_10    0
## ntree_3500_mtry_2     0
## ntree_3500_mtry_4     0
## ntree_3500_mtry_6     0
## ntree_3500_mtry_8     0
## ntree_3500_mtry_10    0
## ntree_4500_mtry_2     0
## ntree_4500_mtry_4     0
## ntree_4500_mtry_6     0
## ntree_4500_mtry_8     0
## ntree_4500_mtry_10    0
# Load necessary libraries
library(ggplot2)

# Define the number of trees and mtry values
n_trees <- c(500, 500, 500, 500, 500,
             1500, 1500, 1500, 1500, 1500,
             2500, 2500, 2500, 2500, 2500,
             3500, 3500, 3500, 3500, 3500,
             4500, 4500, 4500, 4500, 4500)

mtry_values <- rep(c(2, 4, 6, 8, 10), 5)

# Mean accuracy values for each combination of ntree and mtry
mean_accuracies <- c(0.9532479, 0.9489957, 0.9465171, 0.9482479, 0.9498932,
                     0.9549145, 0.9473932, 0.9524145, 0.9507265, 0.9523291,
                     0.9523932, 0.9498718, 0.9514744, 0.9490598, 0.9506624,
                     0.9557692, 0.9499359, 0.9482479, 0.9491239, 0.9507906,
                     0.9516239, 0.9499145, 0.9507051, 0.9506624, 0.9507479)

# Create a data frame for plotting
plot_data <- data.frame(ntrees = n_trees, mtry = mtry_values, accuracy = mean_accuracies)

# Plot with ggplot2
ggplot(plot_data, aes(x = ntrees, y = accuracy, color = as.factor(mtry))) +
  geom_line() +         # Line plot
  geom_point() +        # Points on the line
  labs(title = "Mean Accuracy vs Number of Trees for Different mtry Values",
       x = "Number of Trees (ntree)",
       y = "Mean Accuracy",
       color = "mtry") +
  theme_minimal()       # Minimal theme for a clean look

dotplot(results)

# Load necessary libraries
library(ggplot2)

# Define the data
ntree_values <- c(rep(500, 5), rep(1500, 5), rep(2500, 5), rep(3500, 5), rep(4500, 5))
mtry_values <- rep(c(2, 4, 6, 8, 10), 5)
mean_accuracies <- c(0.9532479, 0.9489957, 0.9465171, 0.9482479, 0.9498932,
                     0.9549145, 0.9473932, 0.9524145, 0.9507265, 0.9523291,
                     0.9523932, 0.9498718, 0.9514744, 0.9490598, 0.9506624,
                     0.9557692, 0.9499359, 0.9482479, 0.9491239, 0.9507906,
                     0.9516239, 0.9499145, 0.9507051, 0.9506624, 0.9507479)

# Create a data frame for plotting
plot_data <- data.frame(ntree = factor(ntree_values), mtry = factor(mtry_values), accuracy = mean_accuracies)

# Plot with ggplot2
ggplot(plot_data, aes(x = mtry, y = ntree, fill = accuracy)) +
  geom_tile(color = "white") +  # Create tiles with white borders
  scale_fill_gradient(low = "white", high = "blue") +  # Gradient color scale
  labs(title = "Heatmap of Mean Accuracy by Number of Trees and mtry",
       x = "mtry",
       y = "Number of Trees (ntree)",
       fill = "Mean Accuracy") +
  theme_minimal() +  # Minimal theme for a clean look
  theme(axis.text.x = element_text(angle = 45, hjust = 1))  # Angle x-axis labels for readability

chosenNTree <- 3500
chosenmtry <- bestmtry$mtry
rf_ <- randomForest(trainData, y=trainData$diagnosis, data=trainData, proximity=TRUE, ntree=chosenNTree,nodesize=2,importance=TRUE, mtry=chosenmtry)
print(rf_)
## 
## Call:
##  randomForest(x = trainData, y = trainData$diagnosis, ntree = chosenNTree,      mtry = chosenmtry, nodesize = 2, importance = TRUE, proximity = TRUE,      data = trainData) 
##                Type of random forest: classification
##                      Number of trees: 3500
## No. of variables tried at each split: 4
## 
##         OOB estimate of  error rate: 0.75%
## Confusion matrix:
##     B   M class.error
## B 249   1  0.00400000
## M   2 147  0.01342282
importance(rf_, type=1)
##                         MeanDecreaseAccuracy
## diagnosis                          71.101031
## radius_mean                        20.525906
## texture_mean                       16.774487
## perimeter_mean                     20.229724
## area_mean                          23.093348
## smoothness_mean                    15.802729
## compactness_mean                   13.051200
## concavity_mean                     23.417504
## concave.points_mean                27.304953
## symmetry_mean                       5.875787
## fractal_dimension_mean              8.093922
## radius_se                          17.726080
## texture_se                          3.521332
## perimeter_se                       16.701481
## area_se                            24.018449
## smoothness_se                       8.205297
## compactness_se                      9.484645
## concavity_se                       11.949030
## concave.points_se                  10.574872
## symmetry_se                         3.947371
## fractal_dimension_se                8.821390
## radius_worst                       30.070275
## texture_worst                      19.144128
## perimeter_worst                    31.573565
## area_worst                         29.758342
## smoothness_worst                   21.514254
## compactness_worst                  15.616311
## concavity_worst                    23.992580
## concave.points_worst               30.897505
## symmetry_worst                     14.453829
## fractal_dimension_worst            11.645477
predictions <- predict(rf_, newdata = testData)
confusionMatrix(predictions, testData$diagnosis)
## Confusion Matrix and Statistics
## 
##           Reference
## Prediction   B   M
##          B 107   0
##          M   0  63
##                                      
##                Accuracy : 1          
##                  95% CI : (0.9785, 1)
##     No Information Rate : 0.6294     
##     P-Value [Acc > NIR] : < 2.2e-16  
##                                      
##                   Kappa : 1          
##                                      
##  Mcnemar's Test P-Value : NA         
##                                      
##             Sensitivity : 1.0000     
##             Specificity : 1.0000     
##          Pos Pred Value : 1.0000     
##          Neg Pred Value : 1.0000     
##              Prevalence : 0.6294     
##          Detection Rate : 0.6294     
##    Detection Prevalence : 0.6294     
##       Balanced Accuracy : 1.0000     
##                                      
##        'Positive' Class : B          
## 
table(predictions, testData$diagnosis)
##            
## predictions   B   M
##           B 107   0
##           M   0  63