Package weka.classifiers.misc
Class InputMappedClassifier
- java.lang.Object
-
- weka.classifiers.AbstractClassifier
-
- weka.classifiers.SingleClassifierEnhancer
-
- weka.classifiers.misc.InputMappedClassifier
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,Classifier,AdditionalMeasureProducer,BatchPredictor,CapabilitiesHandler,CapabilitiesIgnorer,CommandlineRunnable,Drawable,EnvironmentHandler,OptionHandler,RevisionHandler,WeightedInstancesHandler
public class InputMappedClassifier extends SingleClassifierEnhancer implements java.io.Serializable, OptionHandler, Drawable, WeightedInstancesHandler, AdditionalMeasureProducer, EnvironmentHandler
Wrapper classifier that addresses incompatible training and test data by building a mapping between the training data that a classifier has been built with and the incoming test instances' structure. Model attributes that are not found in the incoming instances receive missing values, so do incoming nominal attribute values that the classifier has not seen before. A new classifier can be trained or an existing one loaded from a file. Valid options are:-I Ignore case when matching attribute names and nominal values.
-M Suppress the output of the mapping report.
-trim Trim white space from either end of names before matching.
-L <path to model to load> Path to a model to load. If set, this model will be used for prediction and any base classifier specification will be ignored. Environment variables may be used in the path (e.g. ${HOME}/myModel.model)-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.rules.ZeroR)
Options specific to classifier weka.classifiers.rules.ZeroR:
-D If set, classifier is run in debug mode and may output additional info to the console
- Version:
- $Revision: 15212 $
- Author:
- Mark Hall (mhall{[at]}pentaho{[dot]}com)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class weka.classifiers.AbstractClassifier
BATCH_SIZE_DEFAULT, NUM_DECIMAL_PLACES_DEFAULT
-
Fields inherited from interface weka.core.Drawable
BayesNet, Newick, NOT_DRAWABLE, TREE
-
-
Constructor Summary
Constructors Constructor Description InputMappedClassifier()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildClassifier(Instances data)Build the classifierdoubleclassifyInstance(Instance inst)Classifies the given test instance.InstanceconstructMappedInstance(Instance incoming)double[]distributionForInstance(Instance inst)Predicts the class memberships for a given instance.java.util.Enumeration<java.lang.String>enumerateMeasures()Returns an enumeration of the additional measure namesCapabilitiesgetCapabilities()Returns default capabilities of the classifier.booleangetIgnoreCaseForNames()Get whether to ignore case when matching attribute names and nominal values.intgetMappedClassIndex()doublegetMeasure(java.lang.String additionalMeasureName)Returns the value of the named measureInstancesgetModelHeader(Instances defaultH)Return the instance structure that the encapsulated model was built with.java.lang.StringgetModelPath()Get the path used for loading a model.java.lang.String[]getOptions()Gets the current settings of the Classifier.java.lang.StringgetRevision()Returns the revision string.booleangetSuppressMappingReport()Get whether to suppress output the report of model to input mappings.booleangetTrim()Get whether to trim white space from each end of names before matching.java.lang.StringglobalInfo()Returns a string describing this classifierjava.lang.Stringgraph()Returns graph describing the classifier (if possible).intgraphType()Returns the type of graph this classifier represents.java.lang.StringignoreCaseForNamesTipText()Returns the tip text for this propertyjava.util.Enumeration<Option>listOptions()Returns an enumeration describing the available options.static voidmain(java.lang.String[] argv)Main method for testing this class.java.lang.StringmodelPathTipText()Returns the tip text for this propertyvoidsetEnvironment(Environment env)Set the environment variables to usevoidsetIgnoreCaseForNames(boolean ignore)Set whether to ignore case when matching attribute names and nominal values.voidsetModelHeader(Instances modelHeader)Set the structure of the data used to create the model.voidsetModelPath(java.lang.String modelPath)Set the path from which to load a model.voidsetOptions(java.lang.String[] options)Parses a given list of options.voidsetSuppressMappingReport(boolean suppress)Set whether to suppress output the report of model to input mappings.voidsetTestStructure(Instances testStructure)Set the test structure (if known in advance) that we are likely to see.voidsetTrim(boolean trim)Set whether to trim white space from each end of names before matching.java.lang.StringsuppressMappingReportTipText()Returns the tip text for this propertyjava.lang.StringtoString()java.lang.StringtrimTipText()Returns the tip text for this property-
Methods inherited from class weka.classifiers.SingleClassifierEnhancer
classifierTipText, getClassifier, postExecution, preExecution, setClassifier
-
Methods inherited from class weka.classifiers.AbstractClassifier
batchSizeTipText, debugTipText, distributionsForInstances, doNotCheckCapabilitiesTipText, forName, getBatchSize, getDebug, getDoNotCheckCapabilities, getNumDecimalPlaces, implementsMoreEfficientBatchPrediction, makeCopies, makeCopy, numDecimalPlacesTipText, run, runClassifier, setBatchSize, setDebug, setDoNotCheckCapabilities, setNumDecimalPlaces
-
-
-
-
Method Detail
-
globalInfo
public java.lang.String globalInfo()
Returns a string describing this classifier- Returns:
- a description of the classifier suitable for displaying in the explorer/experimenter gui
-
setEnvironment
public void setEnvironment(Environment env)
Set the environment variables to use- Specified by:
setEnvironmentin interfaceEnvironmentHandler- Parameters:
env- the environment variables to use
-
ignoreCaseForNamesTipText
public java.lang.String ignoreCaseForNamesTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setIgnoreCaseForNames
public void setIgnoreCaseForNames(boolean ignore)
Set whether to ignore case when matching attribute names and nominal values.- Parameters:
ignore- true if case is to be ignored
-
getIgnoreCaseForNames
public boolean getIgnoreCaseForNames()
Get whether to ignore case when matching attribute names and nominal values.- Returns:
- true if case is to be ignored.
-
trimTipText
public java.lang.String trimTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setTrim
public void setTrim(boolean trim)
Set whether to trim white space from each end of names before matching.- Parameters:
trim- true to trim white space.
-
getTrim
public boolean getTrim()
Get whether to trim white space from each end of names before matching.- Returns:
- true if white space is to be trimmed.
-
suppressMappingReportTipText
public java.lang.String suppressMappingReportTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setSuppressMappingReport
public void setSuppressMappingReport(boolean suppress)
Set whether to suppress output the report of model to input mappings.- Parameters:
suppress- true to suppress this output.
-
getSuppressMappingReport
public boolean getSuppressMappingReport()
Get whether to suppress output the report of model to input mappings.- Returns:
- true if this output is to be suppressed.
-
modelPathTipText
public java.lang.String modelPathTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setModelPath
public void setModelPath(java.lang.String modelPath) throws java.lang.ExceptionSet the path from which to load a model. Loading occurs when the first test instance is received or getModelHeader() is called programatically. Environment variables can be used in the supplied path - e.g. ${HOME}/myModel.model.- Parameters:
modelPath- the path to the model to load.- Throws:
java.lang.Exception- if a problem occurs during loading.
-
getModelPath
public java.lang.String getModelPath()
Get the path used for loading a model.- Returns:
- the path used for loading a model.
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilitiesin interfaceCapabilitiesHandler- Specified by:
getCapabilitiesin interfaceClassifier- Overrides:
getCapabilitiesin classSingleClassifierEnhancer- Returns:
- the capabilities of this classifier
- See Also:
Capabilities
-
listOptions
public java.util.Enumeration<Option> listOptions()
Returns an enumeration describing the available options. Valid options are:-I Ignore case when matching attribute names and nominal values.
-M Suppress the output of the mapping report.
-trim Trim white space from either end of names before matching.
-L <path to model to load> Path to a model to load. If set, this model will be used for prediction and any base classifier specification will be ignored. Environment variables may be used in the path (e.g. ${HOME}/myModel.model)-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.rules.ZeroR)
Options specific to classifier weka.classifiers.rules.ZeroR:
-D If set, classifier is run in debug mode and may output additional info to the console
- Specified by:
listOptionsin interfaceOptionHandler- Overrides:
listOptionsin classSingleClassifierEnhancer- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.ExceptionParses a given list of options. Valid options are:-I Ignore case when matching attribute names and nominal values.
-M Suppress the output of the mapping report.
-trim Trim white space from either end of names before matching.
-L <path to model to load> Path to a model to load. If set, this model will be used for prediction and any base classifier specification will be ignored. Environment variables may be used in the path (e.g. ${HOME}/myModel.model)-D If set, classifier is run in debug mode and may output additional info to the console
-W Full name of base classifier. (default: weka.classifiers.rules.ZeroR)
Options specific to classifier weka.classifiers.rules.ZeroR:
-D If set, classifier is run in debug mode and may output additional info to the console
Options after -- are passed to the designated classifier.- Specified by:
setOptionsin interfaceOptionHandler- Overrides:
setOptionsin classSingleClassifierEnhancer- Parameters:
options- the list of options as an array of strings- Throws:
java.lang.Exception- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the Classifier.- Specified by:
getOptionsin interfaceOptionHandler- Overrides:
getOptionsin classSingleClassifierEnhancer- Returns:
- an array of strings suitable for passing to setOptions
-
setTestStructure
public void setTestStructure(Instances testStructure)
Set the test structure (if known in advance) that we are likely to see. If set, then a call to buildClassifier() will not overwrite any test structure that has been recorded with the current training structure. This is useful for getting a correct mapping report output in toString() after buildClassifier has been called and before any test instance has been seen. Test structure and mapping will get reset if a test instance is received whose structure does not match the recorded test structure.- Parameters:
testStructure- the structure of the test instances that we are likely to see (if known in advance)
-
setModelHeader
public void setModelHeader(Instances modelHeader)
Set the structure of the data used to create the model. This method is useful for clients who have an existing in-memory model that they'd like to wrap in the InputMappedClassifier- Parameters:
modelHeader- the structure of the data used to build the wrapped model
-
buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
Build the classifier- Specified by:
buildClassifierin interfaceClassifier- Parameters:
data- the training data to be used for generating the bagged classifier.- Throws:
java.lang.Exception- if the classifier could not be built successfully
-
getModelHeader
public Instances getModelHeader(Instances defaultH) throws java.lang.Exception
Return the instance structure that the encapsulated model was built with. If the classifier will be built from scratch by InputMappedClassifier then this method just returns the default structure that is passed in as argument.- Parameters:
defaultH- the default instances structure- Returns:
- the instances structure used to create the encapsulated model
- Throws:
java.lang.Exception- if a problem occurs
-
getMappedClassIndex
public int getMappedClassIndex() throws java.lang.Exception- Throws:
java.lang.Exception
-
constructMappedInstance
public Instance constructMappedInstance(Instance incoming) throws java.lang.Exception
- Throws:
java.lang.Exception
-
classifyInstance
public double classifyInstance(Instance inst) throws java.lang.Exception
Description copied from class:AbstractClassifierClassifies the given test instance. The instance has to belong to a dataset when it's being classified. Note that a classifier MUST implement either this or distributionForInstance().- Specified by:
classifyInstancein interfaceClassifier- Overrides:
classifyInstancein classAbstractClassifier- Parameters:
inst- the instance to be classified- Returns:
- the predicted most likely class for the instance or Utils.missingValue() if no prediction is made
- Throws:
java.lang.Exception- if an error occurred during the prediction
-
distributionForInstance
public double[] distributionForInstance(Instance inst) throws java.lang.Exception
Description copied from class:AbstractClassifierPredicts the class memberships for a given instance. If an instance is unclassified, the returned array elements must be all zero. If the class is numeric, the array must consist of only one element, which contains the predicted value. Note that a classifier MUST implement either this or classifyInstance().- Specified by:
distributionForInstancein interfaceClassifier- Overrides:
distributionForInstancein classAbstractClassifier- Parameters:
inst- the instance to be classified- Returns:
- an array containing the estimated membership probabilities of the test instance in each class or the numeric prediction
- Throws:
java.lang.Exception- if distribution could not be computed successfully
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
graphType
public int graphType()
Returns the type of graph this classifier represents.
-
enumerateMeasures
public java.util.Enumeration<java.lang.String> enumerateMeasures()
Returns an enumeration of the additional measure names- Specified by:
enumerateMeasuresin interfaceAdditionalMeasureProducer- Returns:
- an enumeration of the measure names
-
getMeasure
public double getMeasure(java.lang.String additionalMeasureName)
Returns the value of the named measure- Specified by:
getMeasurein interfaceAdditionalMeasureProducer- Parameters:
additionalMeasureName- the name of the measure to query for its value- Returns:
- the value of the named measure
- Throws:
java.lang.IllegalArgumentException- if the named measure is not supported
-
graph
public java.lang.String graph() throws java.lang.ExceptionReturns graph describing the classifier (if possible).
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevisionin interfaceRevisionHandler- Overrides:
getRevisionin classAbstractClassifier- Returns:
- the revision
-
main
public static void main(java.lang.String[] argv)
Main method for testing this class.- Parameters:
argv- should contain the following arguments: -t training file [-T test file] [-c class index]
-
-