|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectLBJ2.classify.Classifier
LBJ2.learn.Learner
LBJ2.learn.WekaWrapper
public class WekaWrapper
Translates LBJ's internal problem representation into that which can be handled by WEKA learning algorithms.
WEKA must be available on your CLASSPATH in order to use
this class. WEKA source code and pre-compiled jar distributions are
available at:
http://www.cs.waikato.ac.nz/ml/weka/
To use this class in with clause of a learning classifier
expression, the following restrictions must be recognized:
using clause.
using clause.
To use this class in a Java application, the following restrictions must be recognized:
doneLearning() must be called before calls to
classify(Object) can be made.
So, to retrain a classifier learned with this learner,
forget() must first be called. Then, retraining is accomplished
with calls to either learn(Object) or Learner.learn(Object[]).
Finally, doneLearning() must be called before any calls to
classify(Object) or *Value(Object) methods (e.g.
Classifier.discreteValue(Object)).
On the other hand, if the LBJ compiler took care of training the
learning classifier and no additional training is required, calls to
classify(Object) or *Value(Object) methods may be
made immediately in the application. If additional training is desired,
simply call either learn(Object) or Learner.learn(Object[]), but
don't forget to call doneLearning() before any calls to
classify(Object) or *Value(Object) methods (e.g.
Classifier.discreteValue(Object)).
| Nested Class Summary | |
|---|---|
static class |
WekaWrapper.Parameters
Simply a container for all of WekaWrapper's configurable
parameters. |
| Field Summary | |
|---|---|
protected weka.core.FastVector |
attributeInfo
Information about the features this learner takes as input is parsed from an attribute string and stored here. |
protected weka.classifiers.Classifier |
baseClassifier
Stores the instance of the WEKA classifier which we are training; default is weka.classifiers.bayes.NaiveBayes. |
static java.lang.String |
defaultAttributeString
Default attribute string. |
protected weka.classifiers.Classifier |
freshClassifier
Stores a fresh instance of the WEKA classifier for the purposes of forgetting. |
protected weka.core.Instances |
instances
The main collection of Instance objects. |
protected boolean |
trained
Indicates whether the doneLearning() method has been called
and the forget() method has not yet been called. |
| Fields inherited from class LBJ2.learn.Learner |
|---|
extractor, labeler |
| Fields inherited from class LBJ2.classify.Classifier |
|---|
containingPackage, name |
| Constructor Summary | |
|---|---|
WekaWrapper()
Empty constructor. |
|
WekaWrapper(weka.classifiers.Classifier base)
Partial constructor; attribute information must be provided before any learning can occur. |
|
WekaWrapper(weka.classifiers.Classifier base,
java.lang.String attributeString)
Redirecting constructor. |
|
WekaWrapper(java.lang.String n)
Empty constructor. |
|
WekaWrapper(java.lang.String n,
weka.classifiers.Classifier base)
Partial constructor; attribute information must be provided before any learning can occur. |
|
WekaWrapper(java.lang.String n,
weka.classifiers.Classifier base,
java.lang.String attributeString)
Full Constructor. |
|
WekaWrapper(java.lang.String n,
java.lang.String attributeString)
Default Constructor. |
|
WekaWrapper(java.lang.String n,
WekaWrapper.Parameters p)
Initializing constructor. |
|
WekaWrapper(WekaWrapper.Parameters p)
Initializing constructor. |
|
| Method Summary | |
|---|---|
FeatureVector |
classify(java.lang.Object example)
This method makes one or more decisions about a single object, returning those decisions as Features in a vector. |
void |
doneLearning()
Indicates that the classifier is finished learning. |
void |
forget()
Destroys the learned version of the WEKA classifier and empties the instances collection of examples. |
Classifier |
getExtractor()
Returns the extractor. |
Classifier |
getLabeler()
Returns the labeler. |
void |
initializeAttributes(java.lang.String attributeString)
Takes attributeString and initializes this wrapper's
instances collection to take those attributes. |
void |
learn(java.lang.Object example)
Since WEKA classifiers cannot learn online, this method causes no actual learning to occur, it simply creates an Instance object
from this example and adds it to a set of examples from which the
classifier will be built once doneLearning() is called. |
private weka.core.Instance |
makeInstance(FeatureVector example,
FeatureVector labels)
Creates a WEKA Instance object out of a FeatureVector. |
ScoreSet |
scores(java.lang.Object example)
Produces a set of scores indicating the degree to which each possible discrete classification value is associated with the given example object. |
void |
setExtractor(Classifier e)
Sets the extractor. |
void |
setLabeler(Classifier l)
Sets the labeler. |
void |
write(java.io.PrintStream out)
Writes the settings of the classifier in use, and a string describing the classifier, if available. |
| Methods inherited from class LBJ2.learn.Learner |
|---|
learn, save |
| Methods inherited from class LBJ2.classify.Classifier |
|---|
allowableValues, binaryRead, binaryRead, binaryRead, binaryRead, binaryWrite, binaryWrite, classify, clone, discreteValue, discreteValueArray, getCompositeChildren, getInputType, getOutputType, realValue, realValueArray, test, toString, valueIndexOf |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String defaultAttributeString
protected weka.classifiers.Classifier baseClassifier
weka.classifiers.bayes.NaiveBayes.
protected weka.classifiers.Classifier freshClassifier
protected weka.core.FastVector attributeInfo
learn(Object) method can be called.
Here is an example of a valid attribute string:
nom_SimpleLabel_1,2,3,:str_First:nom_Second_a,b,c,d,r,t,:num_Third:
nom stands for "Nominal", i.e. the feature
SimpleLabel was declared as discrete, and had
the value list {"1","2","3"}.
str stands for "Stirng", i.e. the feature
First was declared to be discrete, but was not
provided with a value list. When using the WekaWrapper, it
is best to provide value lists whenever possible, because very few WEKA
classifiers can handle string attributes.
num stands for "Numerical", i.e. the feature
Third was declared to be real.
protected weka.core.Instances instances
protected boolean trained
doneLearning() method has been called
and the forget() method has not yet been called.
| Constructor Detail |
|---|
public WekaWrapper()
weka.classifiers.bayes.NaiveBayes. Attribute
information must be provided before any learning can occur.
public WekaWrapper(weka.classifiers.Classifier base)
base - The classifier to be used in this system.
public WekaWrapper(weka.classifiers.Classifier base,
java.lang.String attributeString)
base - The classifier to be used in this system.attributeString - The string describing the types of attributes
example objects will have.public WekaWrapper(WekaWrapper.Parameters p)
WekaWrapper.Parameters object.
p - The settings of all parameters.public WekaWrapper(java.lang.String n)
weka.classifiers.bayes.NaiveBayes. Attribute
information must be provided before any learning can occur.
n - The name of the classifier.
public WekaWrapper(java.lang.String n,
weka.classifiers.Classifier base)
base - The classifier to be used in this system.
public WekaWrapper(java.lang.String n,
java.lang.String attributeString)
weka.classifiers.bayes.NaiveBayes.
n - The name of the classifier.attributeString - The string describing the types of attributes
example objects will have.
public WekaWrapper(java.lang.String n,
WekaWrapper.Parameters p)
WekaWrapper.Parameters object.
n - The name of the classifier.p - The settings of all parameters.
public WekaWrapper(java.lang.String n,
weka.classifiers.Classifier base,
java.lang.String attributeString)
n - The name of the classifierbase - The classifier to be used in this system.attributeString - The string describing the types of attributes
example objects will have.| Method Detail |
|---|
public void initializeAttributes(java.lang.String attributeString)
attributeString and initializes this wrapper's
instances collection to take those attributes.
public Classifier getLabeler()
getLabeler in class Learnerpublic void setLabeler(Classifier l)
setLabeler in class Learnerl - A labeling classifier.public Classifier getExtractor()
getExtractor in class Learnerpublic void setExtractor(Classifier e)
setExtractor in class Learnere - A feature extracting classifier.public void learn(java.lang.Object example)
Instance object
from this example and adds it to a set of examples from which the
classifier will be built once doneLearning() is called.
learn in class Learnerexample - An example of the desired learned classifier's behavior.public FeatureVector classify(java.lang.Object example)
classify in class Classifierexample - The object to make decisions about.
Features about the input object.public void forget()
instances collection of examples.
forget in class Learner
private weka.core.Instance makeInstance(FeatureVector example,
FeatureVector labels)
FeatureVector.
public ScoreSet scores(java.lang.Object example)
scores in class Learnerexample - The object to make decisions about.
public void write(java.io.PrintStream out)
write in class Learnerout - The output stream.public void doneLearning()
buildClassifier(Instances) method.
doneLearning in class Learner
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||