|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.classifiers.EnsembleLibraryModel
weka.classifiers.meta.ensembleSelection.EnsembleSelectionLibraryModel
public class EnsembleSelectionLibraryModel
This class represents a library model that is used for EnsembleSelection. At this level the concept of cross validation is abstracted away. This class keeps track of the performance statistics and bookkeeping information for its "model type" accross all the CV folds. By "model type", I mean the combination of both the Classifier type (e.g. J48), and its set of parameters (e.g. -C 0.5 -X 1 -Y 5). So for example, if you are using 5 fold cross validaiton, this model will keep an array of classifiers[] of length 5 and will keep track of their performances accordingly. This class also has methods to deal with serializing all of this information into the .elm file that will represent this model.
Also it is worth mentioning that another important function of this class is to track all of the dataset information that was used to create this model. This is because we want to protect users from doing foreseeably bad things. e.g., trying to build an ensemble for a dataset with models that were trained on the wrong partitioning of the dataset. This could lead to artificially high performance due to the fact that instances used for the test set to gauge performance could have accidentally been used to train the base classifiers. So in a nutshell, we are preventing people from unintentionally "cheating" by enforcing that the seed, #folds, validation ration, and the checksum of the Instances.toString() method ALL match exactly. Otherwise we throw an exception.
Field Summary | |
---|---|
static java.lang.String |
FILE_EXTENSION
The default file extension for ensemble library models |
boolean |
m_Debug
The debug flag as propagated from the main EnsembleSelection class. |
Constructor Summary | |
---|---|
EnsembleSelectionLibraryModel()
Default Constructor |
|
EnsembleSelectionLibraryModel(Classifier classifier)
Basic Constructor |
|
EnsembleSelectionLibraryModel(Classifier classifier,
int seed,
java.lang.String checksum,
double validationRatio,
int folds)
Constructor for LibaryModel |
Method Summary | |
---|---|
void |
createModel(Instances[] data,
Instances[] hillclimbData,
java.lang.String dataDirectoryName,
int algorithm)
Creates the model. |
double[] |
getAveragePrediction(Instance instance)
Returns the average of the prediction of the models across all folds. |
java.lang.String |
getChecksum()
get the checksum |
static java.lang.String |
getFileName(java.lang.String stringRepresentation)
The purpose of this method is to get an appropriate file name for a model based on its string representation of a model. |
double[] |
getFoldPrediction(Instance instance,
int fold)
Returns prediction of the classifier for the specified fold. |
int |
getFolds()
get the number of folds |
Classifier[] |
getModels()
Returs the array of classifiers |
java.lang.String |
getRevision()
Returns the revision string. |
int |
getSeed()
Get the seed |
static java.lang.String |
getStringChecksum(java.lang.String string)
Gets a checksum for the string defining this classifier. |
double[][] |
getValidationPredictions()
getter for validation predictions |
double |
getValidationRatio()
get validationRatio |
static EnsembleSelectionLibraryModel |
loadModel(java.lang.String modelFilePath)
loads the specified model |
void |
rehydrateModel(java.lang.String workingDirectory)
The purpose of this method is to "rehydrate" the classifier object fot this library model from the filesystem. |
void |
releaseModel()
Releases the model from memory. |
static void |
saveModel(java.lang.String directory,
EnsembleSelectionLibraryModel model)
Saves the given model to the specified file. |
void |
setChecksum(java.lang.String instancesChecksum)
set the checksum |
void |
setDebug(boolean debug)
This is used to propagate the m_Debug flag of the EnsembleSelection classifier to this class. |
void |
setFileName(java.lang.String fileName)
Sets the .elm file name for this library model |
void |
setFolds(int folds)
Set the number of folds for cross validation. |
void |
setSeed(int seed)
Set the seed |
void |
setValidationPredictions(double[][] predictions)
setter for validation predictions |
void |
setValidationRatio(double validationRatio)
Sets the validation set ratio (only meaningful if folds == 1) |
void |
train(Instances trainData,
int fold)
Train the classifier for the specified fold on the given data |
Methods inherited from class weka.classifiers.EnsembleLibraryModel |
---|
getClassifier, getDescriptionText, getErrorText, getModelClass, getOptions, getOptionsWereValid, getStringRepresentation, setDescriptionText, setErrorText, setOptionsWereValid, testOptions, toString, updateDescriptionText |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String FILE_EXTENSION
public transient boolean m_Debug
Constructor Detail |
---|
public EnsembleSelectionLibraryModel()
public EnsembleSelectionLibraryModel(Classifier classifier, int seed, java.lang.String checksum, double validationRatio, int folds)
classifier
- the classifier to useseed
- the random seed valuechecksum
- the checksumvalidationRatio
- the ration to usefolds
- the number of folds to usepublic EnsembleSelectionLibraryModel(Classifier classifier)
classifier
- the classifier to useMethod Detail |
---|
public void setDebug(boolean debug)
debug
- if true additional information is outputpublic double[] getAveragePrediction(Instance instance) throws java.lang.Exception
instance
- the instance to get predictions for
java.lang.Exception
- if something goes wrongpublic double[] getFoldPrediction(Instance instance, int fold) throws java.lang.Exception
instance
- instance for which to make a prediction.fold
- fold number of the classifier to use.
java.lang.Exception
- if prediction failspublic void createModel(Instances[] data, Instances[] hillclimbData, java.lang.String dataDirectoryName, int algorithm) throws java.lang.Exception
data
- the data to work withhillclimbData
- the data for hillclimbingdataDirectoryName
- the directory to usealgorithm
- the type of algorithm
java.lang.Exception
- if something goeds wrongpublic void rehydrateModel(java.lang.String workingDirectory)
workingDirectory
- the working directory to usepublic void releaseModel()
public void train(Instances trainData, int fold) throws java.lang.Exception
trainData
- the data to train withfold
- the fold number
java.lang.Exception
- if something goes wrong, e.g., out of memorypublic void setSeed(int seed)
seed
- the seed valuepublic int getSeed()
public void setValidationRatio(double validationRatio)
validationRatio
- the new rationpublic double getValidationRatio()
public void setFolds(int folds)
folds
- the number of folds to usepublic int getFolds()
public void setChecksum(java.lang.String instancesChecksum)
instancesChecksum
- the new checksumpublic java.lang.String getChecksum()
public Classifier[] getModels()
public void setFileName(java.lang.String fileName)
fileName
- the new filenamepublic static java.lang.String getStringChecksum(java.lang.String string)
string
- the classifier definition
public static java.lang.String getFileName(java.lang.String stringRepresentation)
stringRepresentation
- string representation of model
public static void saveModel(java.lang.String directory, EnsembleSelectionLibraryModel model)
directory
- the directory to save the model tomodel
- the model to savepublic static EnsembleSelectionLibraryModel loadModel(java.lang.String modelFilePath)
modelFilePath
- the path of the model
public double[][] getValidationPredictions()
public void setValidationPredictions(double[][] predictions)
predictions
- the new validation predictionspublic java.lang.String getRevision()
getRevision
in interface RevisionHandler
getRevision
in class EnsembleLibraryModel
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |