Description Usage Arguments Details Value Note Author(s) References See Also Examples
Computes k-fold cross validation for rminer models.
1 2 3 | crossvaldata(x, data, theta.fit, theta.predict, ngroup = 10,
mode = "stratified", seed = NULL, model, task, feature = "none",
...)
|
x |
See |
data |
See |
theta.fit |
fitting function |
theta.predict |
prediction function |
ngroup |
number of folds |
mode |
Possibilities are: "stratified", "random" or "order" (see |
seed |
if |
model |
See |
task |
See |
feature |
See |
... |
Additional parameters sent to |
Standard k-fold cross-validation adopted for rminer models.
By default, for classification tasks ("class" or "prob") a stratified sampling is used
(the class distributions are identical for each fold), unless mode
is set to random
or order
(see holdout
for details).
Returns a list with:
$cv.fit – all predictions (factor if task="class"
, matrix if task="prob"
or numeric if task="reg"
);
$model – vector list with the model for each fold.
$mpar – vector list with the mpar for each fold;
$attributes – the selected attributes for each fold if a feature selection algorithm was adopted;
$ngroup – the number of folds;
$leave.out – the computed size for each fold (=nrow(data)/ngroup
);
$groups – vector list with the indexes of each group;
$call – the call of this function;
A better control (e.g. use of several Runs) is achieved using the simpler mining
function.
This function was adapted by Paulo Cortez from the crossval
function of the bootstrap library (S original by R. Tibshirani and R port by F. Leisch).
Check the crossval
function of the bootstrap library.
holdout
, fit
, mining
and predict.fit
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ### dontrun is used when the execution of the example requires some computational effort.
## Not run:
data(iris)
# 3-fold cross validation using fit and predict
# the control argument is sent to rpart function
# rpart.control() is from the rpart package
M=crossvaldata(Species~.,iris,fit,predict,ngroup=3,seed=12345,model="rpart",
task="prob", control = rpart::rpart.control(cp=0.05))
print("cross validation object:")
print(M)
C=mmetric(iris$Species,M$cv.fit,metric="CONF")
print("confusion matrix:")
print(C)
## End(Not run)
|
[1] "cross validation object:"
$cv.fit
[,1] [,2] [,3]
[1,] 1 0.00000000 0.00000000
[2,] 1 0.00000000 0.00000000
[3,] 1 0.00000000 0.00000000
[4,] 1 0.00000000 0.00000000
[5,] 1 0.00000000 0.00000000
[6,] 1 0.00000000 0.00000000
[7,] 1 0.00000000 0.00000000
[8,] 1 0.00000000 0.00000000
[9,] 1 0.00000000 0.00000000
[10,] 1 0.00000000 0.00000000
[11,] 1 0.00000000 0.00000000
[12,] 1 0.00000000 0.00000000
[13,] 1 0.00000000 0.00000000
[14,] 1 0.00000000 0.00000000
[15,] 1 0.00000000 0.00000000
[16,] 1 0.00000000 0.00000000
[17,] 1 0.00000000 0.00000000
[18,] 1 0.00000000 0.00000000
[19,] 1 0.00000000 0.00000000
[20,] 1 0.00000000 0.00000000
[21,] 1 0.00000000 0.00000000
[22,] 1 0.00000000 0.00000000
[23,] 1 0.00000000 0.00000000
[24,] 1 0.00000000 0.00000000
[25,] 1 0.00000000 0.00000000
[26,] 1 0.00000000 0.00000000
[27,] 1 0.00000000 0.00000000
[28,] 1 0.00000000 0.00000000
[29,] 1 0.00000000 0.00000000
[30,] 1 0.00000000 0.00000000
[31,] 1 0.00000000 0.00000000
[32,] 1 0.00000000 0.00000000
[33,] 1 0.00000000 0.00000000
[34,] 1 0.00000000 0.00000000
[35,] 1 0.00000000 0.00000000
[36,] 1 0.00000000 0.00000000
[37,] 1 0.00000000 0.00000000
[38,] 1 0.00000000 0.00000000
[39,] 1 0.00000000 0.00000000
[40,] 1 0.00000000 0.00000000
[41,] 1 0.00000000 0.00000000
[42,] 1 0.00000000 0.00000000
[43,] 1 0.00000000 0.00000000
[44,] 1 0.00000000 0.00000000
[45,] 1 0.00000000 0.00000000
[46,] 1 0.00000000 0.00000000
[47,] 1 0.00000000 0.00000000
[48,] 1 0.00000000 0.00000000
[49,] 1 0.00000000 0.00000000
[50,] 1 0.00000000 0.00000000
[51,] 0 0.89189189 0.10810811
[52,] 0 0.97142857 0.02857143
[53,] 0 0.97142857 0.02857143
[54,] 0 0.94117647 0.05882353
[55,] 0 0.94117647 0.05882353
[56,] 0 0.94117647 0.05882353
[57,] 0 0.94117647 0.05882353
[58,] 0 0.89189189 0.10810811
[59,] 0 0.97142857 0.02857143
[60,] 0 0.89189189 0.10810811
[61,] 0 0.97142857 0.02857143
[62,] 0 0.89189189 0.10810811
[63,] 0 0.97142857 0.02857143
[64,] 0 0.97142857 0.02857143
[65,] 0 0.94117647 0.05882353
[66,] 0 0.97142857 0.02857143
[67,] 0 0.89189189 0.10810811
[68,] 0 0.94117647 0.05882353
[69,] 0 0.97142857 0.02857143
[70,] 0 0.94117647 0.05882353
[71,] 0 0.00000000 1.00000000
[72,] 0 0.89189189 0.10810811
[73,] 0 0.94117647 0.05882353
[74,] 0 0.94117647 0.05882353
[75,] 0 0.89189189 0.10810811
[76,] 0 0.94117647 0.05882353
[77,] 0 0.97142857 0.02857143
[78,] 0 0.00000000 1.00000000
[79,] 0 0.89189189 0.10810811
[80,] 0 0.89189189 0.10810811
[81,] 0 0.97142857 0.02857143
[82,] 0 0.97142857 0.02857143
[83,] 0 0.89189189 0.10810811
[84,] 0 0.00000000 1.00000000
[85,] 0 0.97142857 0.02857143
[86,] 0 0.89189189 0.10810811
[87,] 0 0.94117647 0.05882353
[88,] 0 0.94117647 0.05882353
[89,] 0 0.97142857 0.02857143
[90,] 0 0.97142857 0.02857143
[91,] 0 0.94117647 0.05882353
[92,] 0 0.97142857 0.02857143
[93,] 0 0.89189189 0.10810811
[94,] 0 0.89189189 0.10810811
[95,] 0 0.89189189 0.10810811
[96,] 0 0.89189189 0.10810811
[97,] 0 0.94117647 0.05882353
[98,] 0 0.89189189 0.10810811
[99,] 0 0.94117647 0.05882353
[100,] 0 0.94117647 0.05882353
[101,] 0 0.00000000 1.00000000
[102,] 0 0.00000000 1.00000000
[103,] 0 0.03225806 0.96774194
[104,] 0 0.03225806 0.96774194
[105,] 0 0.03225806 0.96774194
[106,] 0 0.03225806 0.96774194
[107,] 0 0.97142857 0.02857143
[108,] 0 0.00000000 1.00000000
[109,] 0 0.03225806 0.96774194
[110,] 0 0.03225806 0.96774194
[111,] 0 0.00000000 1.00000000
[112,] 0 0.00000000 1.00000000
[113,] 0 0.00000000 1.00000000
[114,] 0 0.00000000 1.00000000
[115,] 0 0.00000000 1.00000000
[116,] 0 0.03225806 0.96774194
[117,] 0 0.00000000 1.00000000
[118,] 0 0.00000000 1.00000000
[119,] 0 0.03225806 0.96774194
[120,] 0 0.89189189 0.10810811
[121,] 0 0.00000000 1.00000000
[122,] 0 0.94117647 0.05882353
[123,] 0 0.00000000 1.00000000
[124,] 0 0.94117647 0.05882353
[125,] 0 0.00000000 1.00000000
[126,] 0 0.00000000 1.00000000
[127,] 0 0.00000000 1.00000000
[128,] 0 0.94117647 0.05882353
[129,] 0 0.00000000 1.00000000
[130,] 0 0.97142857 0.02857143
[131,] 0 0.00000000 1.00000000
[132,] 0 0.00000000 1.00000000
[133,] 0 0.00000000 1.00000000
[134,] 0 0.97142857 0.02857143
[135,] 0 0.97142857 0.02857143
[136,] 0 0.03225806 0.96774194
[137,] 0 0.00000000 1.00000000
[138,] 0 0.00000000 1.00000000
[139,] 0 0.94117647 0.05882353
[140,] 0 0.00000000 1.00000000
[141,] 0 0.03225806 0.96774194
[142,] 0 0.03225806 0.96774194
[143,] 0 0.00000000 1.00000000
[144,] 0 0.00000000 1.00000000
[145,] 0 0.03225806 0.96774194
[146,] 0 0.03225806 0.96774194
[147,] 0 0.00000000 1.00000000
[148,] 0 0.03225806 0.96774194
[149,] 0 0.00000000 1.00000000
[150,] 0 0.03225806 0.96774194
$model
$model[[1]]
[1] "rpart"
$model[[2]]
[1] "rpart"
$model[[3]]
[1] "rpart"
$mpar
$mpar[[1]]
$mpar[[1]]$control
$mpar[[1]]$control$minsplit
[1] 20
$mpar[[1]]$control$minbucket
[1] 7
$mpar[[1]]$control$cp
[1] 0.05
$mpar[[1]]$control$maxcompete
[1] 4
$mpar[[1]]$control$maxsurrogate
[1] 5
$mpar[[1]]$control$usesurrogate
[1] 2
$mpar[[1]]$control$surrogatestyle
[1] 0
$mpar[[1]]$control$maxdepth
[1] 30
$mpar[[1]]$control$xval
[1] 10
$mpar[[1]]$method
[1] "class"
$mpar[[2]]
$mpar[[2]]$control
$mpar[[2]]$control$minsplit
[1] 20
$mpar[[2]]$control$minbucket
[1] 7
$mpar[[2]]$control$cp
[1] 0.05
$mpar[[2]]$control$maxcompete
[1] 4
$mpar[[2]]$control$maxsurrogate
[1] 5
$mpar[[2]]$control$usesurrogate
[1] 2
$mpar[[2]]$control$surrogatestyle
[1] 0
$mpar[[2]]$control$maxdepth
[1] 30
$mpar[[2]]$control$xval
[1] 10
$mpar[[2]]$method
[1] "class"
$mpar[[3]]
$mpar[[3]]$control
$mpar[[3]]$control$minsplit
[1] 20
$mpar[[3]]$control$minbucket
[1] 7
$mpar[[3]]$control$cp
[1] 0.05
$mpar[[3]]$control$maxcompete
[1] 4
$mpar[[3]]$control$maxsurrogate
[1] 5
$mpar[[3]]$control$usesurrogate
[1] 2
$mpar[[3]]$control$surrogatestyle
[1] 0
$mpar[[3]]$control$maxdepth
[1] 30
$mpar[[3]]$control$xval
[1] 10
$mpar[[3]]$method
[1] "class"
$sen
NULL
$sresponses
[1] FALSE
$attributes
NULL
$ngroup
[1] 3
$leave.out
[1] 50
$groups
$groups[[1]]
[1] 142 51 58 93 75 96 2 86 146 38 103 94 10 40 141 30 1 72 12
[20] 3 14 106 119 16 80 62 145 98 116 60 105 32 25 36 104 150 136 9
[39] 5 79 83 17 109 37 148 67 110 13 95 120
$groups[[2]]
[1] 49 74 56 91 34 44 35 143 149 55 23 26 97 7 15 46 132 112 68
[20] 11 100 101 99 147 87 42 88 4 73 128 57 65 48 78 108 131 18 122
[39] 138 54 76 31 70 125 20 84 124 133 139 6
$groups[[3]]
[1] 90 47 53 135 59 52 137 29 118 115 28 111 102 117 8 130 64 123 21
[20] 71 77 140 24 81 19 121 39 63 33 113 45 107 50 27 61 85 82 129
[39] 41 43 144 66 92 134 126 114 127 69 22 89
[1] "confusion matrix:"
$res
NULL
$conf
pred
target setosa versicolor virginica
setosa 50 0 0
versicolor 0 47 3
virginica 0 9 41
$roc
NULL
$lift
NULL
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.