Description Usage Arguments Value Examples
This is a learning algorithm that uses cross-validation to select the number of neighbors that minimizes the mean validation loss
1 2 |
X.mat |
a training data set |
y.vec |
a training data set |
max.neighbors=30 |
The max number of neighbors to fin the best k in nearest neighbors |
fold.vec=NULL |
is a vector of fold ID numbers. If fold.vec is NULL randomly assign fold IDs from 1 to n.folds |
n.folds=5 |
is the number of folds used to compute error |
returnList a list containing: X.mat - training data y.vec - training data train.loss.mat - matrice of loss values for each fold and number of neighbors validation.loss.mat - matrice of loss values for each fold and number of neighbors train.loss.vec - vector with max.neighbors elements: mean loss over all folds validation.loss.vec - vector with max.neighbors elements: mean loss over all folds selected.neighbors - number of neighbors selected by minimizing the mean validation loss predict(testX.mat) - a function that takes a matrix of inputs/features and returns a vector of predictions. It should check the type/dimension of testX.mat and stop() with an informative error message if there are any issues.
1 2 3 4 5 6 7 8 9 10 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.