mardi 10 décembre 2019

Split 100 times randomly train and test data using caret in R

I classify a satellite image using Random Forest in R. To better estimate the accuracy of the classifier, I would like to carry out classification procedure which will be repeated 100 times with randomly changing sets of training and test samples (divided 50% by class). I don't know how to split this sets randomly and repeat it 100 times.

    #extracted - data frame contains extracted values of pixels

    set.seed(100)

    trainIndeks <- caret::createDataPartition(extracted$class, p = 0.5, list=FALSE, times = 1)
    dataTrain <- extracted[trainIndeks,]
    dataTest <- extracted[-trainIndeks,]

    dataTrain_px <- dataTrain[, 1:numberofbands]
    dataTrain_labels <- dataTrain[, ncol(dataTrain)]

    dataTest_px <- dataTest[, 1:numberofbands]
    dataTest_labels <- dataTest[, ncol(dataTrain)]

    table(dataTrain_labels)
    table(dataTest_labels)



Aucun commentaire:

Enregistrer un commentaire