mercredi 7 novembre 2018

How can I look at a specific generated train and test sets made from for loop?

My program divides my dataset into train and test set, builds a decision tree based on the train and test set and calculates the accuracy, sensitivity and the specifity of the confusion matrix.

I added a for loop to rerun my program 100 times. This means I get 100 train and test sets. The output of the for loop is a result_df with columns of accuracy, specifity and sensitivity.

This is the for loop:

result_df<-matrix(ncol=3,nrow=100)
colnames(result_df)<-c("Acc","Sens","Spec")

for (g in 1:100 )
{

  # Divide into Train and test set
  smp_size <- floor(0.8 * nrow(mydata1))
  train_ind <- sample(seq_len(nrow(mydata1)), size = smp_size)
  train <- mydata1[train_ind, ]
  test <- mydata1[-train_ind, ]

  REST OF MY CODE

}

My result_df (first 20 rows) looks like this:

> result_df[1:20,]
   Acc Sens Spec id
1   26   22   29  1
2   10   49   11  2
3   37   43   36  3
4    4   79    4  4
5   21   21   20  5
6   31   17   34  6
7   57    4   63  7
8   33    3   39  8
9   56   42   59  9
10  65   88   63 10
11   6   31    7 11
12  57   44   62 12
13  25   10   27 13
14  32   24   32 14
15  19    8   19 15
16  27   27   29 16
17  38   89   33 17
18  54   32   56 18
19  35   62   33 19
20  37    6   40 20

I use ggplot() to plot the specifity and the sensitivity as a scatterplot:

enter image description here

What I want to do :

I want to see e.g. the train and test set of datapoint 17.

I think I can do this by using the set.seed function, but I am very unfamiliar with this function.




Aucun commentaire:

Enregistrer un commentaire