int[] trainy = Math.slice(y, cv.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);
/** * Leave-one-out cross validation of a classification model. * * @param <T> the data type of input objects. * @param trainer a classifier trainer that is properly parameterized. * @param x the test data set. * @param y the test data labels. * @return the accuracy on test dataset */ public static <T> double loocv(ClassifierTrainer<T> trainer, T[] x, int[] y) { int m = 0; int n = x.length; LOOCV loocv = new LOOCV(n); for (int i = 0; i < n; i++) { T[] trainx = Math.slice(x, loocv.train[i]); int[] trainy = Math.slice(y, loocv.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy); if (classifier.predict(x[loocv.test[i]]) == y[loocv.test[i]]) { m++; } } return (double) m / n; }
int[] trainy = Math.slice(y, cv.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);
int[] trainy = Math.slice(y, bootstrap.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);
int[] trainy = Math.slice(y, bootstrap.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);
int[] trainy = Math.slice(y, cv.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);
/** * Leave-one-out cross validation of a classification model. * * @param <T> the data type of input objects. * @param trainer a classifier trainer that is properly parameterized. * @param x the test data set. * @param y the test data labels. * @param measure the performance measure of classification. * @return the test results with the same size of order of measures */ public static <T> double loocv(ClassifierTrainer<T> trainer, T[] x, int[] y, ClassificationMeasure measure) { int n = x.length; int[] predictions = new int[n]; LOOCV loocv = new LOOCV(n); for (int i = 0; i < n; i++) { T[] trainx = Math.slice(x, loocv.train[i]); int[] trainy = Math.slice(y, loocv.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy); predictions[loocv.test[i]] = classifier.predict(x[loocv.test[i]]); } return measure.measure(y, predictions); }
int[] trainy = Math.slice(y, bootstrap.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);
return Validation.cv(k, trainer, xx, y); } else { Classifier<double[]> classifier = trainer.train(xx, y);
int[] trainy = Math.slice(y, loocv.train[i]); Classifier<T> classifier = trainer.train(trainx, trainy);