public class NFoldCrossValidation<T> extends java.lang.Object implements CrossValidation, BalancedCrossValidation, MultipleEvaluatorCrossValidation<T>
Class for performing N-Fold Cross-validation.
The list of samples used is taken in order. Let us consider 10 folds. For the first fold, the first 10% are used for testing, and the remaining 90% are used for training. For the second fold, the second 10% are used for testing, and the remaining for training, and so on. Warning, no randomization is performed on the list, so be careful it is not in the order of the classes which would bias the learning. This CV is balanced by default
Constructor and Description |
---|
NFoldCrossValidation(int n,
Classifier<T> cls,
java.util.List<TrainingSample<T>> l,
Evaluator<T> eval)
Default constructor with number of folds, classifier, full samples list and evaluation metric.
|
Modifier and Type | Method and Description |
---|---|
void |
addEvaluator(java.lang.String name,
Evaluator<T> e)
Register a new evaluator to this corssvalidation
|
double |
getAverageScore()
Tells the average score of the test
|
double |
getAverageScore(java.lang.String name)
Tells the average score of the test for the given evaluator
|
double[] |
getScores()
Tells the scores of the tests, in order of evaluation
|
double[] |
getScores(java.lang.String name)
Tells the scores of the tests, in order of evaluation for the given evaluator
|
double |
getStdDevScore()
Tells the standard deviation of the test
|
double |
getStdDevScore(java.lang.String name)
Tells the standard deviation of the test for the given evaluator
|
boolean |
isBalanced()
Returns true if the splits are balanced between positive and negative
|
void |
removeEvaluator(java.lang.String name)
unregister the evaluator by its name
|
void |
run()
perform learning and evaluations
|
void |
setBalanced(boolean balanced)
Set class balancing strategy when computing the splits
|
public NFoldCrossValidation(int n, Classifier<T> cls, java.util.List<TrainingSample<T>> l, Evaluator<T> eval)
n
- the number of foldscls
- the classifier to evaluatel
- the full list of sampleeval
- the evaluation metric to compute on each foldpublic void run()
CrossValidation
run
in interface CrossValidation
public double getAverageScore()
CrossValidation
getAverageScore
in interface CrossValidation
public double getStdDevScore()
CrossValidation
getStdDevScore
in interface CrossValidation
public double[] getScores()
CrossValidation
getScores
in interface CrossValidation
public boolean isBalanced()
isBalanced
in interface BalancedCrossValidation
public void setBalanced(boolean balanced)
setBalanced
in interface BalancedCrossValidation
balanced
- true if enables balancingpublic void addEvaluator(java.lang.String name, Evaluator<T> e)
MultipleEvaluatorCrossValidation
addEvaluator
in interface MultipleEvaluatorCrossValidation<T>
name
- a string associated with this evaluatore
- the evaluatorpublic void removeEvaluator(java.lang.String name)
MultipleEvaluatorCrossValidation
removeEvaluator
in interface MultipleEvaluatorCrossValidation<T>
name
- the name of the evaluatorpublic double getAverageScore(java.lang.String name)
MultipleEvaluatorCrossValidation
getAverageScore
in interface MultipleEvaluatorCrossValidation<T>
name
- name of the evaluatorpublic double getStdDevScore(java.lang.String name)
MultipleEvaluatorCrossValidation
getStdDevScore
in interface MultipleEvaluatorCrossValidation<T>
name
- name of the evaluatorpublic double[] getScores(java.lang.String name)
MultipleEvaluatorCrossValidation
getScores
in interface MultipleEvaluatorCrossValidation<T>
name
- of the evaluator