public class CVLearningCurve
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected Classifier |
classifier
The classifier for which K-fold CV learning curve has to be generated
|
protected boolean |
debug
Flag for debug display
|
protected static double[] |
DEFAULT_POINTS
Default points
|
protected java.util.Vector<Example>[][] |
foldBins
foldBins[i][j] stores the examples for class i in fold j.
|
protected int |
numClasses
Number of classes in the data
|
protected int |
numFolds
Number of folds of cross validation to run
|
protected double[] |
points
Points on the X axis (percentage of train data) to plot
|
protected long |
randomSeed
Seed for random number generator
|
protected PointResults[] |
testResults
Accuracy results for test data, one PointResults for each point on the curve
|
protected double |
testTime
Total Testing time
|
protected int |
testTimeNum
Total number of examples tested in test time
|
protected java.util.Vector<Example>[] |
totalExamples
Stores all the examples for each class
|
protected int |
totalNumTrain
Total number of training examples per fold
|
protected PointResults[] |
trainResults
Accuracy results for training data, one PointResults for each point on the curve
|
protected double |
trainTime
Total Training time
|
Constructor and Description |
---|
CVLearningCurve(Classifier c,
java.util.List<Example> examples)
Creates a CVLearning curve object with 10 folds and default points
|
CVLearningCurve(int nfolds,
Classifier c,
java.util.List<Example> examples,
double[] points,
long randomSeed,
boolean debug)
Creates a CVLearning curve object
|
Modifier and Type | Method and Description |
---|---|
void |
binExamples()
Set the fold Bins from the total Examples -- this effectively
stores the training-test split
|
Classifier |
getClassifier()
Return classifier
|
java.util.Vector<Example>[][] |
getFoldBins()
Return the fold Bins
|
java.util.Vector<Example> |
getTestCV(int foldnum)
Creates the testing set for one fold of a cross-validation
on the dataset.
|
java.util.Vector[] |
getTotalExamples()
Return all the examples
|
java.util.Vector<Example> |
getTrainCV(int foldnum,
double percent)
Creates the training set for one fold of a cross-validation
on the dataset.
|
void |
run()
Run a CV learning curve test and print total training and test time
and generate an averge learning curve plot output files suitable
for gunuplot
|
void |
setClassifier(Classifier c)
Set the classifier
|
void |
setFoldBins(java.util.Vector<Example>[][] bins)
Set the fold Bins
|
void |
setTotalExamples(java.util.List<Example> examples)
Sets the totalExamples by partitioning examples into categories to
get a stratified sample
|
void |
setTotalExamples(java.util.Vector<Example>[] data)
Set all the examples
|
protected int |
sizeOfFold(int foldNum)
Computes the total number of examples in given fold
|
void |
trainAndTest()
Run training and test for each point to be plotted, gathering a result for
each fold.
|
void |
trainAndTestFold(java.util.Vector<Example> train,
java.util.Vector<Example> test,
int fold,
PointResults testPointResults,
PointResults trainPointResults)
Train and test on given example sets for the given fold:
|
protected java.util.Vector<Example>[] totalExamples
protected java.util.Vector<Example>[][] foldBins
protected Classifier classifier
protected long randomSeed
protected int numClasses
protected int totalNumTrain
protected int numFolds
protected double[] points
protected static double[] DEFAULT_POINTS
protected boolean debug
protected double trainTime
protected double testTime
protected int testTimeNum
protected PointResults[] testResults
protected PointResults[] trainResults
public CVLearningCurve(int nfolds, Classifier c, java.util.List<Example> examples, double[] points, long randomSeed, boolean debug)
nfolds
- Number of folds of CV to performc
- Classifier on which to perform K-fold CVexamples
- List of examples.points
- Points (in percentage of full train set) to plot on learning curvedebug
- Debugging flag to set verbose trace printingpublic CVLearningCurve(Classifier c, java.util.List<Example> examples)
c
- Classifier on which to perform K-fold CVexamples
- List of examples.public Classifier getClassifier()
public void setClassifier(Classifier c)
public java.util.Vector[] getTotalExamples()
public void setTotalExamples(java.util.Vector<Example>[] data)
public java.util.Vector<Example>[][] getFoldBins()
public void setFoldBins(java.util.Vector<Example>[][] bins)
public void setTotalExamples(java.util.List<Example> examples)
public void run() throws java.lang.Exception
java.lang.Exception
public void trainAndTest()
public void trainAndTestFold(java.util.Vector<Example> train, java.util.Vector<Example> test, int fold, PointResults testPointResults, PointResults trainPointResults)
train
- The training dataset vectortest
- The testing dataset vectorfold
- The current fold numbertestPointResults
- train accuracy PointResults for this pointtrainPointResults
- test accuracy PointResults for this pointpublic void binExamples()
public java.util.Vector<Example> getTrainCV(int foldnum, double percent)
foldnum
- The fold for which training set is to be constructedpercent
- Percentage of examples to use for training in this foldprotected int sizeOfFold(int foldNum)
public java.util.Vector<Example> getTestCV(int foldnum)
foldnum
- The fold which is to be used as testing data