|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.classify.TrainableClassifier
de.fu_berlin.ties.classify.OneAgainstTheRestClassifier
public class OneAgainstTheRestClassifier
This classifier converts an multi-class classification task into a several binary (two-class) classification task. It wraps several instances of another classifier that are used to perform the binary classifications and combines their results.
When used with N classes, this classifier created and wrapped N inner binary classifiers. Each inner classifier classifiers between members (positive instances) and non-members (negative instances) of a specified class. The inner classifier returning the highest probability for its (positive) class wins, even if the negative class of that classifier would be still higher. This is the classical "one-against-the-rest" (or "one-against-all") setup.
This classifier differs from
MultiBinaryClassifier
in not using a
"background class" and using N inner classifiers, while
MultiBinaryClassifier
uses N-1.
Instances of this class are thread-safe if and only if instances of the wrapped classifier are.
WARNING: The current implementation does
not query the shouldTrain
method of inner classifiers.
Because of this, classifiers overwriting shouldTrain
might not
work correctly within this classifier.
Field Summary |
---|
Fields inherited from class de.fu_berlin.ties.classify.TrainableClassifier |
---|
META_CLASSIFIER, MULTI_CLASSIFIER, OAR_CLASSIFIER |
Fields inherited from interface de.fu_berlin.ties.classify.Classifier |
---|
CONFIG_CLASSIFIER |
Constructor Summary | |
---|---|
OneAgainstTheRestClassifier(Set<String> allValidClasses,
FeatureTransformer trans,
File runDirectory,
String[] innerSpec,
TiesConfiguration conf)
Creates a new instance. |
Method Summary | |
---|---|
protected Set<String> |
createBinarySet(String baseClass)
Helper method that creates a set containing the two classes of a binary classifier. |
protected PredictionDistribution |
doClassify(FeatureVector features,
Set candidateClasses,
ContextMap context)
Classifies an item that is represented by a feature vector by choosing the most probable class among a set of candidate classes. This implementation combines the predictions for the positive class of all involved inner classifiers. |
protected void |
doTrain(FeatureVector features,
String targetClass,
ContextMap context)
Incorporates an item that is represented by a feature vector into the classification model. |
void |
reset()
Resets the classifer, completely deleting the prediction model. |
String |
toString()
Returns a string representation of this object. |
protected boolean |
trainOnErrorHook(PredictionDistribution predDist,
FeatureVector features,
String targetClass,
Set candidateClasses,
ContextMap context)
Subclasses can implement this hook for more refined error-driven learning. |
Methods inherited from class de.fu_berlin.ties.classify.TrainableClassifier |
---|
classify, createClassifier, createClassifier, createClassifier, createClassifier, getAllClasses, getConfig, shouldTrain, toElement, train, trainOnError |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public OneAgainstTheRestClassifier(Set<String> allValidClasses, FeatureTransformer trans, File runDirectory, String[] innerSpec, TiesConfiguration conf) throws IllegalArgumentException, ProcessingException
allValidClasses
- the set of all valid classestrans
- the last transformer in the transformer chain to use, or
null
if no feature transformers should be usedrunDirectory
- optional run directory passed to inner classifiers
of the ExternalClassifier
typeinnerSpec
- the specification used to initialize the inner
classifiers, passed to the
TrainableClassifier.createClassifier(Set, File,
FeatureTransformer, String[], TiesConfiguration)
factory methodconf
- used to configure this instance and the inner classifiers
IllegalArgumentException
- if there are fewer than three classes
(in which case you should use the inner classifier directly since there
is no need to wrap several instances)
ProcessingException
- if an error occurred while creating this
classifier or one of the wrapped classifiersMethod Detail |
---|
protected Set<String> createBinarySet(String baseClass)
baseClass
- the base class to use
protected PredictionDistribution doClassify(FeatureVector features, Set candidateClasses, ContextMap context) throws ProcessingException
The probability estimates returned by each classifier are used "as is", so the result will not be a real probability distribution because sum of all probabilities will be more than 1. If you want to work on a real probability distribution you have normalize it yourself.
doClassify
in class TrainableClassifier
features
- the feature vector to considercandidateClasses
- an set of classes that are allowed for this itemcontext
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
PredictionDistribution.best()
to get the most probably class
ProcessingException
- if an error occurs during classificationprotected void doTrain(FeatureVector features, String targetClass, ContextMap context) throws ProcessingException
doTrain
in class TrainableClassifier
features
- the feature vector to considertargetClass
- the class of this feature vectorcontext
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
ProcessingException
- if an error occurs during trainingpublic String toString()
toString
in class TrainableClassifier
protected boolean trainOnErrorHook(PredictionDistribution predDist, FeatureVector features, String targetClass, Set candidateClasses, ContextMap context) throws ProcessingException
TrainableClassifier.trainOnError(FeatureVector, String, Set)
method after
classifying. This method can do any necessary training itself and
return true
to signal that no further action is necessary.
This implementation is just a placeholder that always returns
false
.
trainOnErrorHook
in class TrainableClassifier
predDist
- the prediction distribution returned by
TrainableClassifier.classify(FeatureVector, Set)
features
- the feature vector to considertargetClass
- the expected class of this feature vector; must be
contained in the set of candidateClasses
candidateClasses
- an set of classes that are allowed for this item
(the actual targetClass
must be one of them)context
- can be used to transport implementation-specific
contextual information between the
TrainableClassifier.doClassify(FeatureVector, Set, ContextMap)
,
TrainableClassifier.doTrain(FeatureVector, String, ContextMap)
, and
TrainableClassifier.trainOnErrorHook(PredictionDistribution, FeatureVector, String,
Set, ContextMap)
methods
false
; subclasses
can return true
to signal that any error-driven learning was
already handled
ProcessingException
- if an error occurs during trainingpublic void reset() throws ProcessingException
reset
in class TrainableClassifier
ProcessingException
- if an error occurs during reset
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |