Package moa.classifiers
Class AbstractClassifier
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
- Direct Known Subclasses:
AbstractAMRules
,AbstractMultiLabelLearner
,AccuracyUpdatedEnsemble
,AccuracyWeightedEnsemble
,AdaptiveNodePredictor
,AdaptiveRandomForest
,AdaptiveRandomForestRegressor
,ADOB
,ALRandom
,ALUncertainty
,ARFFIMTDD
,Autoencoder
,BinaryClassifierFromRegressor
,BOLE
,CAND
,ChangeDetectorLearner
,ClassifierWithFeatureImportance
,CSMOTE
,DACC
,DecisionStump
,DriftDetectionMethodClassifier
,DynamicWeightedMajority
,EFDT
,FeatureImportanceHoeffdingTree
,FeatureImportanceHoeffdingTreeEnsemble
,FIMTDD
,HeterogeneousEnsembleAbstract
,HoeffdingOptionTree
,HoeffdingTree
,HSTrees
,Iadem2
,kNN
,LearnNSE
,LeveragingBag
,LimAttClassifier
,LowPassFilteredLearner
,MajorityClass
,MLP
,NaiveBayes
,NaiveBayesMultinomial
,NearestNeighbourDescription
,NoChange
,OCBoost
,OnlineAccuracyUpdatedEnsemble
,OnlineAdaBoost
,OnlineAdaC2
,OnlineCSB2
,OnlineRUSBoost
,OnlineSmoothBoost
,OnlineSMOTEBagging
,OnlineUnderOverBagging
,OzaBag
,OzaBagAdwin
,OzaBagASHT
,OzaBoost
,OzaBoostAdwin
,PairedLearners
,Perceptron
,Perceptron
,RandomAMRulesOld
,RandomRules
,RebalanceStream
,RuleClassifier
,SAMkNN
,SelfOptimisingBaseTree
,SelfOptimisingKNearestLeaves
,SGD
,SGDMultiClass
,SPegasos
,StreamingGradientBoostedTrees
,StreamingRandomPatches
,TargetMean
,TemporallyAugmentedClassifier
,WeightedMajorityAlgorithm
,WEKAClassifier
public abstract class AbstractClassifier extends AbstractOptionHandler implements Classifier, CapabilitiesHandler
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description Random
classifierRandom
Random Generator used in randomizable learnersprotected InstancesHeader
modelContext
Header of the instances of the data streamprotected int
randomSeed
Random seed used in randomizable learnersprotected IntOption
randomSeedOption
Option for randomizable learners to change the random seedprotected double
trainingWeightSeenByModel
Sum of the weights of the instances trained by this model-
Fields inherited from class moa.options.AbstractOptionHandler
config
-
-
Constructor Summary
Constructors Constructor Description AbstractClassifier()
Creates an classifier and setups the random seed option if the classifier is randomizable.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static boolean
contextIsCompatible(InstancesHeader originalContext, InstancesHeader newContext)
Returns if two contexts or headers of instances are compatible.
Two contexts are compatible if they follow the following rules:
Rule 1: num classes can increase but never decrease
Rule 2: num attributes can increase but never decrease
Rule 3: num nominal attribute values can increase but never decrease
Rule 4: attribute types must stay in the same order (although class can move; is always skipped over)
Attribute names are free to change, but should always still represent the original attributes.Classifier
copy()
This method produces a copy of this object.boolean
correctlyClassifies(Instance inst)
Gets whether this classifier correctly classifies an instance.ImmutableCapabilities
defineImmutableCapabilities()
Defines the set of capabilities the object has.String
getAttributeNameString(int attIndex)
Gets the name of an attribute from the header.AWTRenderer
getAWTRenderer()
Returns the AWT RendererString
getClassLabelString(int classLabelIndex)
Gets the name of a label of the class from the header.String
getClassNameString()
Gets the name of the attribute of the class from the header.void
getDescription(StringBuilder out, int indent)
Returns a string representation of this object.MOAObject
getModel()
Gets the model if this learner.InstancesHeader
getModelContext()
Gets the reference to the header of the data stream.abstract void
getModelDescription(StringBuilder out, int indent)
Returns a string representation of the model.Measurement[]
getModelMeasurements()
Gets the current measurements of this learner.protected abstract Measurement[]
getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.String
getNominalValueString(int attIndex, int valIndex)
Gets the name of a value of an attribute from the header.Prediction
getPredictionForInstance(Instance inst)
Gets the reference to the header of the data stream.Prediction
getPredictionForInstance(Example<Instance> example)
String
getPurposeString()
Dictionary with option texts and objectsClassifier[]
getSubClassifiers()
Gets the classifiers of this ensemble.Learner[]
getSublearners()
Gets the learners of this ensemble.abstract double[]
getVotesForInstance(Instance inst)
Predicts the class memberships for a given instance.double[]
getVotesForInstance(Example<Instance> example)
Predicts the class memberships for a given instance.protected static int
modelAttIndexToInstanceAttIndex(int index, Instance inst)
Gets the index of the attribute in the instance, given the index of the attribute in the learner.protected static int
modelAttIndexToInstanceAttIndex(int index, Instances insts)
Gets the index of the attribute in a set of instances, given the index of the attribute in the learner.void
prepareForUseImpl(TaskMonitor monitor, ObjectRepository repository)
This method describes the implementation of how to prepare this object for use.void
resetLearning()
Resets this learner.abstract void
resetLearningImpl()
Resets this classifier.void
setModelContext(InstancesHeader ih)
Sets the reference to the header of the data stream.void
setRandomSeed(int s)
Sets the seed for random number generation.boolean
trainingHasStarted()
Gets whether training has started.double
trainingWeightSeenByModel()
Gets the sum of the weights of the instances that have been used by this learner during the training intrainOnInstance
void
trainOnInstance(Instance inst)
Trains this learner incrementally using the given example.void
trainOnInstance(Example<Instance> example)
Trains this learner incrementally using the given example.abstract void
trainOnInstanceImpl(Instance inst)
Trains this classifier incrementally using the given instance.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.-
Methods inherited from class moa.options.AbstractOptionHandler
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
-
Methods inherited from class moa.AbstractMOAObject
copy, measureByteSize, measureByteSize, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface moa.capabilities.CapabilitiesHandler
getCapabilities
-
Methods inherited from interface moa.learners.Learner
isRandomizable
-
Methods inherited from interface moa.MOAObject
measureByteSize
-
Methods inherited from interface moa.options.OptionHandler
getCLICreationString, getOptions, prepareForUse, prepareForUse
-
-
-
-
Field Detail
-
modelContext
protected InstancesHeader modelContext
Header of the instances of the data stream
-
trainingWeightSeenByModel
protected double trainingWeightSeenByModel
Sum of the weights of the instances trained by this model
-
randomSeed
protected int randomSeed
Random seed used in randomizable learners
-
randomSeedOption
protected IntOption randomSeedOption
Option for randomizable learners to change the random seed
-
classifierRandom
public Random classifierRandom
Random Generator used in randomizable learners
-
-
Method Detail
-
getPurposeString
public String getPurposeString()
Description copied from class:AbstractOptionHandler
Dictionary with option texts and objects- Specified by:
getPurposeString
in interfaceOptionHandler
- Overrides:
getPurposeString
in classAbstractOptionHandler
- Returns:
- the string with the purpose of this object
-
prepareForUseImpl
public void prepareForUseImpl(TaskMonitor monitor, ObjectRepository repository)
Description copied from class:AbstractOptionHandler
This method describes the implementation of how to prepare this object for use. All classes that extends this class have to implementprepareForUseImpl
and notprepareForUse
sinceprepareForUse
callsprepareForUseImpl
.- Specified by:
prepareForUseImpl
in classAbstractOptionHandler
- Parameters:
monitor
- the TaskMonitor to userepository
- the ObjectRepository to use
-
getVotesForInstance
public double[] getVotesForInstance(Example<Instance> example)
Description copied from interface:Learner
Predicts the class memberships for a given instance. If an instance is unclassified, the returned array elements must be all zero.- Specified by:
getVotesForInstance
in interfaceLearner<Example<Instance>>
- Parameters:
example
- the instance to be classified- Returns:
- an array containing the estimated membership probabilities of the test instance in each class
-
getVotesForInstance
public abstract double[] getVotesForInstance(Instance inst)
Description copied from interface:Classifier
Predicts the class memberships for a given instance. If an instance is unclassified, the returned array elements must be all zero.- Specified by:
getVotesForInstance
in interfaceClassifier
- Parameters:
inst
- the instance to be classified- Returns:
- an array containing the estimated membership probabilities of the test instance in each class
-
getPredictionForInstance
public Prediction getPredictionForInstance(Example<Instance> example)
- Specified by:
getPredictionForInstance
in interfaceLearner<Example<Instance>>
-
getPredictionForInstance
public Prediction getPredictionForInstance(Instance inst)
Description copied from interface:Classifier
Gets the reference to the header of the data stream. The header of the data stream is extended from WEKAInstances
. This header is needed to know the number of classes and attributes- Specified by:
getPredictionForInstance
in interfaceClassifier
- Returns:
- the reference to the data stream header
-
setModelContext
public void setModelContext(InstancesHeader ih)
Description copied from interface:Learner
Sets the reference to the header of the data stream. The header of the data stream is extended from WEKAInstances
. This header is needed to know the number of classes and attributes- Specified by:
setModelContext
in interfaceLearner<Example<Instance>>
- Parameters:
ih
- the reference to the data stream header
-
getModelContext
public InstancesHeader getModelContext()
Description copied from interface:Learner
Gets the reference to the header of the data stream. The header of the data stream is extended from WEKAInstances
. This header is needed to know the number of classes and attributes- Specified by:
getModelContext
in interfaceLearner<Example<Instance>>
- Returns:
- the reference to the data stream header
-
setRandomSeed
public void setRandomSeed(int s)
Description copied from interface:Learner
Sets the seed for random number generation.- Specified by:
setRandomSeed
in interfaceLearner<Example<Instance>>
- Parameters:
s
- the seed
-
trainingHasStarted
public boolean trainingHasStarted()
Description copied from interface:Learner
Gets whether training has started.- Specified by:
trainingHasStarted
in interfaceLearner<Example<Instance>>
- Returns:
- true if training has started
-
trainingWeightSeenByModel
public double trainingWeightSeenByModel()
Description copied from interface:Learner
Gets the sum of the weights of the instances that have been used by this learner during the training intrainOnInstance
- Specified by:
trainingWeightSeenByModel
in interfaceLearner<Example<Instance>>
- Returns:
- the weight of the instances that have been used training
-
resetLearning
public void resetLearning()
Description copied from interface:Learner
Resets this learner. It must be similar to starting a new learner from scratch.- Specified by:
resetLearning
in interfaceLearner<Example<Instance>>
-
trainOnInstance
public void trainOnInstance(Instance inst)
Description copied from interface:Classifier
Trains this learner incrementally using the given example.- Specified by:
trainOnInstance
in interfaceClassifier
- Parameters:
inst
- the instance to be used for training
-
getModelMeasurements
public Measurement[] getModelMeasurements()
Description copied from interface:Learner
Gets the current measurements of this learner.- Specified by:
getModelMeasurements
in interfaceLearner<Example<Instance>>
- Returns:
- an array of measurements to be used in evaluation tasks
-
getDescription
public void getDescription(StringBuilder out, int indent)
Description copied from interface:MOAObject
Returns a string representation of this object. Used inAbstractMOAObject.toString
to give a string representation of the object.- Specified by:
getDescription
in interfaceMOAObject
- Parameters:
out
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
getSublearners
public Learner[] getSublearners()
Description copied from interface:Learner
Gets the learners of this ensemble. Returns null if this learner is a single learner.- Specified by:
getSublearners
in interfaceLearner<Example<Instance>>
- Returns:
- an array of the learners of the ensemble
-
getSubClassifiers
public Classifier[] getSubClassifiers()
Description copied from interface:Classifier
Gets the classifiers of this ensemble. Returns null if this learner is a single learner.- Specified by:
getSubClassifiers
in interfaceClassifier
- Returns:
- an array of the learners of the ensemble
-
copy
public Classifier copy()
Description copied from interface:MOAObject
This method produces a copy of this object.- Specified by:
copy
in interfaceClassifier
- Specified by:
copy
in interfaceMOAObject
- Specified by:
copy
in interfaceOptionHandler
- Overrides:
copy
in classAbstractOptionHandler
- Returns:
- a copy of this object
-
getModel
public MOAObject getModel()
Description copied from interface:Learner
Gets the model if this learner.
-
trainOnInstance
public void trainOnInstance(Example<Instance> example)
Description copied from interface:Learner
Trains this learner incrementally using the given example.- Specified by:
trainOnInstance
in interfaceLearner<Example<Instance>>
- Parameters:
example
- the instance to be used for training
-
correctlyClassifies
public boolean correctlyClassifies(Instance inst)
Description copied from interface:Classifier
Gets whether this classifier correctly classifies an instance. Uses getVotesForInstance to obtain the prediction and the instance to obtain its true class.- Specified by:
correctlyClassifies
in interfaceClassifier
- Parameters:
inst
- the instance to be classified- Returns:
- true if the instance is correctly classified
-
getClassNameString
public String getClassNameString()
Gets the name of the attribute of the class from the header.- Returns:
- the string with name of the attribute of the class
-
getClassLabelString
public String getClassLabelString(int classLabelIndex)
Gets the name of a label of the class from the header.- Parameters:
classLabelIndex
- the label index- Returns:
- the name of the label of the class
-
getAttributeNameString
public String getAttributeNameString(int attIndex)
Gets the name of an attribute from the header.- Parameters:
attIndex
- the attribute index- Returns:
- the name of the attribute
-
getNominalValueString
public String getNominalValueString(int attIndex, int valIndex)
Gets the name of a value of an attribute from the header.- Parameters:
attIndex
- the attribute indexvalIndex
- the value of the attribute- Returns:
- the name of the value of the attribute
-
contextIsCompatible
public static boolean contextIsCompatible(InstancesHeader originalContext, InstancesHeader newContext)
Returns if two contexts or headers of instances are compatible.
Two contexts are compatible if they follow the following rules:
Rule 1: num classes can increase but never decrease
Rule 2: num attributes can increase but never decrease
Rule 3: num nominal attribute values can increase but never decrease
Rule 4: attribute types must stay in the same order (although class can move; is always skipped over)
Attribute names are free to change, but should always still represent the original attributes.- Parameters:
originalContext
- the first context to comparenewContext
- the second context to compare- Returns:
- true if the two contexts are compatible.
-
getAWTRenderer
public AWTRenderer getAWTRenderer()
Returns the AWT Renderer- Specified by:
getAWTRenderer
in interfaceAWTRenderable
- Returns:
- the AWT Renderer
-
resetLearningImpl
public abstract void resetLearningImpl()
Resets this classifier. It must be similar to starting a new classifier from scratch.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.
-
trainOnInstanceImpl
public abstract void trainOnInstanceImpl(Instance inst)
Trains this classifier incrementally using the given instance.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Parameters:
inst
- the instance to be used for training
-
getModelMeasurementsImpl
protected abstract Measurement[] getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Returns:
- an array of measurements to be used in evaluation tasks
-
getModelDescription
public abstract void getModelDescription(StringBuilder out, int indent)
Returns a string representation of the model.- Parameters:
out
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
modelAttIndexToInstanceAttIndex
protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst)
Gets the index of the attribute in the instance, given the index of the attribute in the learner.- Parameters:
index
- the index of the attribute in the learnerinst
- the instance- Returns:
- the index in the instance
-
modelAttIndexToInstanceAttIndex
protected static int modelAttIndexToInstanceAttIndex(int index, Instances insts)
Gets the index of the attribute in a set of instances, given the index of the attribute in the learner.- Parameters:
index
- the index of the attribute in the learnerinsts
- the instances- Returns:
- the index of the attribute in the instances
-
defineImmutableCapabilities
public ImmutableCapabilities defineImmutableCapabilities()
Description copied from interface:CapabilitiesHandler
Defines the set of capabilities the object has. Should be overridden if the object's capabilities do not change.- Specified by:
defineImmutableCapabilities
in interfaceCapabilitiesHandler
- Returns:
- The capabilities of the object.
-
-