jsat.classifiers
Class ClassificationModelEvaluation
- java.lang.Object
-
- jsat.classifiers.ClassificationModelEvaluation
-
public class ClassificationModelEvaluation extends java.lang.ObjectProvides a mechanism to quickly perform an evaluation of a model on a data set. This can be done with cross validation or with a testing set.
-
-
Constructor Summary
Constructors Constructor and Description ClassificationModelEvaluation(Classifier classifier, ClassificationDataSet dataSet)Constructs a new object that can perform evaluations on the model.ClassificationModelEvaluation(Classifier classifier, ClassificationDataSet dataSet, boolean parallel)Constructs a new object that can perform evaluations on the model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddScorer(ClassificationScore scorer)Adds a new score object that will be used as part of the evaluation when callingevaluateCrossValidation(int, java.util.Random)orevaluateTestSet(jsat.classifiers.ClassificationDataSet).booleandoseStoreResults()voidevaluateCrossValidation(int folds)Performs an evaluation of the classifier using the training data set.voidevaluateCrossValidation(int folds, java.util.Random rand)Performs an evaluation of the classifier using the training data set.voidevaluateCrossValidation(java.util.List<ClassificationDataSet> lcds)Performs an evaluation of the classifier using the training data set, where the folds of the training data set are provided by the user.voidevaluateCrossValidation(java.util.List<ClassificationDataSet> lcds, java.util.List<ClassificationDataSet> trainCombinations)Note: Most people should never need to call this method.voidevaluateTestSet(ClassificationDataSet testSet)Performs an evaluation of the classifier using the initial data set to train, and testing on the given data set.ClassifiergetClassifier()Returns the classifier that was original given for evaluation.double[][]getConfusionMatrix()doublegetCorrectWeights()Returns the total value of the weights for data points that were classified correctly.doublegetErrorRate()Computes the weighted error rate of the classifier.OnLineStatisticsgetErrorRateStats()Returns the object that keeps track of the error on individual evaluations.Classifier[]getKeptModels()Returns the models that were kept after the last evaluation.double[]getPointWeights()IfkeepPredictions(boolean)was set, this method will return the array storing the weights for each of the points that were classifiedCategoricalResults[]getPredictions()IfkeepPredictions(boolean)was set, this method will return the array storing the predictions made by the classifier during evaluation.OnLineStatisticsgetScoreStats(ClassificationScore score)Gets the statistics associated with the given score.doublegetSumOfWeights()Returns the total value of the weights for all data points that were tested againstlonggetTotalClassificationTime()Returns the total number of milliseconds spent performing classification on the testing set.longgetTotalTrainingTime()Returns the total number of milliseconds spent training the classifier.int[]getTruths()IfkeepPredictions(boolean)was set, this method will return the array storing the target classes that should have been predicted during evaluation.booleanisKeepModels()This will keep the models trained when evaluating the model.voidkeepPredictions(boolean keepPredictions)Indicates whether or not the predictions made during evaluation should be stored with the expected value for retrieval later.voidprettyPrintClassificationScores()Prints out the classification information in a convenient format.voidprettyPrintConfusionMatrix()Assuming that we are on the start of a new line, the confusion matrix will be pretty printed toSystem.outvoidsetDataTransformProcess(DataTransformProcess dtp)Sets the data transform process to use when performing cross validation.voidsetKeepModels(boolean keepModels)Set this totruein order to keep the trained models after evaluation.voidsetWarmModels(Classifier... warmModels)Sets the models that will be used for warm starting training.
-
-
-
Constructor Detail
-
ClassificationModelEvaluation
public ClassificationModelEvaluation(Classifier classifier, ClassificationDataSet dataSet)
Constructs a new object that can perform evaluations on the model. The model will not be trained until evaluation time.- Parameters:
classifier- the model to train and evaluatedataSet- the training data set.
-
ClassificationModelEvaluation
public ClassificationModelEvaluation(Classifier classifier, ClassificationDataSet dataSet, boolean parallel)
Constructs a new object that can perform evaluations on the model. The model will not be trained until evaluation time.- Parameters:
classifier- the model to train and evaluatedataSet- the training data set.parallel-trueif the training should be done using multiple-cores,falsefor single threaded.
-
-
Method Detail
-
setKeepModels
public void setKeepModels(boolean keepModels)
Set this totruein order to keep the trained models after evaluation. They can then be retrieved used thegetKeptModels()methods. The default value isfalse.- Parameters:
keepModels-trueto keep the trained models after evaluation,falseto discard them.
-
isKeepModels
public boolean isKeepModels()
This will keep the models trained when evaluating the model. The models can be obtained after an evaluation fromgetKeptModels().- Returns:
trueif trained models will be kept after evaluation.
-
getKeptModels
public Classifier[] getKeptModels()
Returns the models that were kept after the last evaluation.nullwill be returned instead ifisKeepModels()returnsfalse, which is the default.- Returns:
- the models that were kept after the last evaluation. Or
nullif if models are not being kept.
-
setWarmModels
public void setWarmModels(Classifier... warmModels)
Sets the models that will be used for warm starting training. If using cross-validation, the number of models given should match the number of folds. If using a test set, only one model should be given.- Parameters:
warmModels- the models to use for warm start training
-
setDataTransformProcess
public void setDataTransformProcess(DataTransformProcess dtp)
Sets the data transform process to use when performing cross validation. By default, no transforms are applied- Parameters:
dtp- the transformation process to clone for use during evaluation
-
evaluateCrossValidation
public void evaluateCrossValidation(int folds)
Performs an evaluation of the classifier using the training data set. The evaluation is done by performing cross validation.- Parameters:
folds- the number of folds for cross validation- Throws:
UntrainedModelException- if the number of folds given is less than 2
-
evaluateCrossValidation
public void evaluateCrossValidation(int folds, java.util.Random rand)Performs an evaluation of the classifier using the training data set. The evaluation is done by performing cross validation.- Parameters:
folds- the number of folds for cross validationrand- the source of randomness for generating the cross validation sets- Throws:
UntrainedModelException- if the number of folds given is less than 2
-
evaluateCrossValidation
public void evaluateCrossValidation(java.util.List<ClassificationDataSet> lcds)
Performs an evaluation of the classifier using the training data set, where the folds of the training data set are provided by the user. The folds do not need to be the same sizes, though it is assumed that they are all approximately the same size. It is the caller's responsibility to ensure that the folds are only from the original training data set.
This method exists so that the user can provide very specific folds if they so desire. This can be useful when there is known bias in the data set, such as when caused by duplicate data point values. The caller can then manually make sure duplicate values all occur in the same fold to avoid over-estimating the accuracy of the model.- Parameters:
lcds- the training data set already split into folds
-
evaluateCrossValidation
public void evaluateCrossValidation(java.util.List<ClassificationDataSet> lcds, java.util.List<ClassificationDataSet> trainCombinations)
Note: Most people should never need to call this method. Make sure you understand what you are doing before you do.
Performs an evaluation of the classifier using the training data set, where the folds of the training data set, and their combinations, are provided by the user. The folds do not need to be the same sizes, though it is assumed that they are all approximately the same size - and the the training combination corresponding to each index will be the sum of the folds in the other indices. It is the caller's responsibility to ensure that the folds are only from the original training data set.
This method exists so that the user can provide very specific folds if they so desire, and when the same folds will be used multiple times. Doing so allows the algorithms called to take advantage of any potential caching of results based on the data set and avoid all possible excessive memory movement. (For example,DataSet.getNumericColumns()may get re-used and benefit from its caching)
The same behavior of this method can be obtained by callingevaluateCrossValidation(java.util.List).- Parameters:
lcds- training data set already split into foldstrainCombinations- each index contains the training data sans the data stored in the fold associated with that index
-
evaluateTestSet
public void evaluateTestSet(ClassificationDataSet testSet)
Performs an evaluation of the classifier using the initial data set to train, and testing on the given data set.- Parameters:
testSet- the data set to perform testing on
-
addScorer
public void addScorer(ClassificationScore scorer)
Adds a new score object that will be used as part of the evaluation when callingevaluateCrossValidation(int, java.util.Random)orevaluateTestSet(jsat.classifiers.ClassificationDataSet). The statistics for the given score are reset on every call, and the mean / standard deviation comes from multiple folds in cross validation.
The score statistics can be obtained fromgetScoreStats(ClassificationScore)after one of the evaluation methods have been called.- Parameters:
scorer- the score method to keep track of.
-
getScoreStats
public OnLineStatistics getScoreStats(ClassificationScore score)
Gets the statistics associated with the given score. If the score is not currently in the model evaluationnullwill be returned. The object passed in does not need to be the exact same object passed toaddScorer(ClassificationScore), it only needs to be equal to the object.- Parameters:
score- the score type to get the result statistics- Returns:
- the result statistics for the given score, or
nullif the score is not in th evaluation set
-
keepPredictions
public void keepPredictions(boolean keepPredictions)
Indicates whether or not the predictions made during evaluation should be stored with the expected value for retrieval later.- Parameters:
keepPredictions- true if space should be allocated to store the predictions made
-
doseStoreResults
public boolean doseStoreResults()
- Returns:
- true if the predictions are being stored
-
getPredictions
public CategoricalResults[] getPredictions()
IfkeepPredictions(boolean)was set, this method will return the array storing the predictions made by the classifier during evaluation. These results may not be in the same order as the data set they came from, but the order is paired withgetTruths()- Returns:
- the array of predictions, or null
-
getTruths
public int[] getTruths()
IfkeepPredictions(boolean)was set, this method will return the array storing the target classes that should have been predicted during evaluation. These results may not be in the same order as the data set they came from, but the order is paired withgetPredictions()- Returns:
- the array of target class values, or null
-
getPointWeights
public double[] getPointWeights()
IfkeepPredictions(boolean)was set, this method will return the array storing the weights for each of the points that were classified- Returns:
- the array of data point weights, or null
-
getConfusionMatrix
public double[][] getConfusionMatrix()
-
prettyPrintConfusionMatrix
public void prettyPrintConfusionMatrix()
Assuming that we are on the start of a new line, the confusion matrix will be pretty printed toSystem.out
-
prettyPrintClassificationScores
public void prettyPrintClassificationScores()
Prints out the classification information in a convenient format. If no additional scores were added via theaddScorer(ClassificationScore)method, nothing will be printed.
-
getCorrectWeights
public double getCorrectWeights()
Returns the total value of the weights for data points that were classified correctly.- Returns:
- the total value of the weights for data points that were classified correctly.
-
getSumOfWeights
public double getSumOfWeights()
Returns the total value of the weights for all data points that were tested against- Returns:
- the total value of the weights for all data points that were tested against
-
getErrorRate
public double getErrorRate()
Computes the weighted error rate of the classifier. If all weights of the data points tested were equal, then the value returned is also the percent of data points that the classifier erred on.- Returns:
- the weighted error rate of the classifier.
-
getErrorRateStats
public OnLineStatistics getErrorRateStats()
Returns the object that keeps track of the error on individual evaluations. If cross-validation was used, it is the statistics for the errors of each fold. If not, it is for each timeevaluateTestSet(jsat.classifiers.ClassificationDataSet)was called.- Returns:
- the statistics for the error of all evaluation sets
-
getTotalTrainingTime
public long getTotalTrainingTime()
Returns the total number of milliseconds spent training the classifier.- Returns:
- the total number of milliseconds spent training the classifier.
-
getTotalClassificationTime
public long getTotalClassificationTime()
Returns the total number of milliseconds spent performing classification on the testing set.- Returns:
- the total number of milliseconds spent performing classification on the testing set.
-
getClassifier
public Classifier getClassifier()
Returns the classifier that was original given for evaluation.- Returns:
- the classifier that was original given for evaluation.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG