public abstract class AbstractClassifier extends AbstractOptionHandler implements Classifier
Modifier and Type | Field and Description |
---|---|
Random |
classifierRandom
Random Generator used in randomizable learners
|
protected double |
downSampleRatio |
protected InstancesHeader |
modelContext
Header of the instances of the data stream
|
protected int |
randomSeed
Random seed used in randomizable learners
|
protected IntOption |
randomSeedOption
Option for randomizable learners to change the random seed
|
protected double |
trainingWeightSeenByModel
Sum of the weights of the instances trained by this model
|
config
Constructor and Description |
---|
AbstractClassifier()
Creates an classifier and setups the random seed option
if the classifier is randomizable.
|
Modifier and Type | Method and 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.
|
String |
getAttributeNameString(int attIndex)
Gets the name of an attribute from the header.
|
AWTRenderer |
getAWTRenderer()
Returns the AWT Renderer
|
String |
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.
|
double |
getDownSampleRatio() |
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(Example<Instance> example) |
Prediction |
getPredictionForInstance(Instance inst)
Gets the reference to the header of the data stream.
|
String |
getPurposeString()
Dictionary with option texts and objects
|
Classifier[] |
getSubClassifiers()
Gets the classifiers of this ensemble.
|
Learner[] |
getSublearners()
Gets the learners of this ensemble.
|
double[] |
getVotesForInstance(Example<Instance> example)
Predicts the class memberships for a given instance.
|
abstract double[] |
getVotesForInstance(Instance inst)
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 in
trainOnInstance |
void |
trainOnInstance(Example<Instance> example)
Trains this learner incrementally using the given example.
|
void |
trainOnInstance(Instance inst)
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. |
void |
updateDownSampleRatio(double downSampleRatio) |
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
copy, measureByteSize, measureByteSize, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isRandomizable
getCLICreationString, getOptions, prepareForUse, prepareForUse
measureByteSize
protected InstancesHeader modelContext
protected double trainingWeightSeenByModel
protected int randomSeed
protected IntOption randomSeedOption
public Random classifierRandom
protected double downSampleRatio
public AbstractClassifier()
public String getPurposeString()
AbstractOptionHandler
getPurposeString
in interface OptionHandler
getPurposeString
in class AbstractOptionHandler
public void prepareForUseImpl(TaskMonitor monitor, ObjectRepository repository)
AbstractOptionHandler
prepareForUseImpl
and not prepareForUse
since
prepareForUse
calls prepareForUseImpl
.prepareForUseImpl
in class AbstractOptionHandler
monitor
- the TaskMonitor to userepository
- the ObjectRepository to usepublic double[] getVotesForInstance(Example<Instance> example)
Learner
getVotesForInstance
in interface Learner<Example<Instance>>
public abstract double[] getVotesForInstance(Instance inst)
Classifier
getVotesForInstance
in interface Classifier
inst
- the instance to be classifiedpublic Prediction getPredictionForInstance(Example<Instance> example)
getPredictionForInstance
in interface Learner<Example<Instance>>
public Prediction getPredictionForInstance(Instance inst)
Classifier
Instances
. This header is needed to know the number of
classes and attributesgetPredictionForInstance
in interface Classifier
public void setModelContext(InstancesHeader ih)
Learner
Instances
.
This header is needed to know the number of classes and attributessetModelContext
in interface Learner<Example<Instance>>
ih
- the reference to the data stream headerpublic InstancesHeader getModelContext()
Learner
Instances
.
This header is needed to know the number of classes and attributesgetModelContext
in interface Learner<Example<Instance>>
public void setRandomSeed(int s)
Learner
setRandomSeed
in interface Learner<Example<Instance>>
s
- the seedpublic boolean trainingHasStarted()
Learner
trainingHasStarted
in interface Learner<Example<Instance>>
public double trainingWeightSeenByModel()
Learner
trainOnInstance
trainingWeightSeenByModel
in interface Learner<Example<Instance>>
public void resetLearning()
Learner
resetLearning
in interface Learner<Example<Instance>>
public void trainOnInstance(Instance inst)
Classifier
trainOnInstance
in interface Classifier
inst
- the instance to be used for trainingpublic Measurement[] getModelMeasurements()
Learner
getModelMeasurements
in interface Learner<Example<Instance>>
public void getDescription(StringBuilder out, int indent)
MOAObject
AbstractMOAObject.toString
to give a string representation of the object.getDescription
in interface MOAObject
out
- the stringbuilder to add the descriptionindent
- the number of characters to indentpublic Learner[] getSublearners()
Learner
getSublearners
in interface Learner<Example<Instance>>
public Classifier[] getSubClassifiers()
Classifier
getSubClassifiers
in interface Classifier
public Classifier copy()
MOAObject
copy
in interface Classifier
copy
in interface MOAObject
copy
in interface OptionHandler
copy
in class AbstractOptionHandler
public MOAObject getModel()
Learner
public void trainOnInstance(Example<Instance> example)
Learner
trainOnInstance
in interface Learner<Example<Instance>>
public boolean correctlyClassifies(Instance inst)
Classifier
correctlyClassifies
in interface Classifier
inst
- the instance to be classifiedpublic String getClassNameString()
public String getClassLabelString(int classLabelIndex)
classLabelIndex
- the label indexpublic String getAttributeNameString(int attIndex)
attIndex
- the attribute indexpublic String getNominalValueString(int attIndex, int valIndex)
attIndex
- the attribute indexvalIndex
- the value of the attributepublic static boolean contextIsCompatible(InstancesHeader originalContext, InstancesHeader newContext)
originalContext
- the first context to comparenewContext
- the second context to comparepublic AWTRenderer getAWTRenderer()
getAWTRenderer
in interface AWTRenderable
public abstract void resetLearningImpl()
public abstract void trainOnInstanceImpl(Instance inst)
inst
- the instance to be used for trainingprotected abstract Measurement[] getModelMeasurementsImpl()
public abstract void getModelDescription(StringBuilder out, int indent)
out
- the stringbuilder to add the descriptionindent
- the number of characters to indentprotected static int modelAttIndexToInstanceAttIndex(int index, Instance inst)
index
- the index of the attribute in the learnerinst
- the instanceprotected static int modelAttIndexToInstanceAttIndex(int index, Instances insts)
index
- the index of the attribute in the learnerinsts
- the instancespublic void updateDownSampleRatio(double downSampleRatio)
public double getDownSampleRatio()
Copyright © 2019 University of Waikato, Hamilton, NZ. All Rights Reserved.