Description Usage Arguments Value Author(s) See Also Examples
Does n-fold cross-validation for fastknn
to find the best k parameter.
1 2 |
x |
input matrix of dimension |
y |
factor array wtih class labels for the |
k |
sequence of possible k values to be evaluated (default is [3:15]). |
method |
the probability estimator as in |
normalize |
variable scaler as in |
folds |
number of folds (default is 5) or an array with fold ids between
1 and |
eval.metric |
classification loss measure to use in cross-validation.
See |
nthread |
the number of CPU threads to use (default is 1). |
list
with cross-validation results:
best_eval
: the best loss measure found in the
cross-validation procedure.
best_k
: the best k value found in the cross-validation procedure.
cv_table
: data.frame
with the test performances for each k
on each data fold.
David Pinto.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## Not run:
library("mlbench")
library("caTools")
library("fastknn")
data("Ionosphere")
x <- data.matrix(subset(Ionosphere, select = -Class))
y <- Ionosphere$Class
set.seed(1024)
tr.idx <- which(sample.split(Y = y, SplitRatio = 0.7))
x.tr <- x[tr.idx,]
x.te <- x[-tr.idx,]
y.tr <- y[tr.idx]
y.te <- y[-tr.idx]
set.seed(2048)
cv.out <- fastknnCV(x = x.tr, y = y.tr, k = c(5,10,15,20), eval.metric="logloss")
cv.out$cv_table
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.