public class WekaWrapper extends Learner
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 the with
clause of a learning classifier expression, the
following restrictions must be recognized:
using
clause.
using
clause.
using
clause may not contain the
underscore character ('_
').
using
clause may
not contain the underscore, colon, or comma characters ('_
', ':
', or '
,
').
To use this class in a Java application, the following restrictions must be recognized:
doneLearning()
must be called before calls to Learner.classify(Object)
can be made.
doneLearning()
is called, Learner.learn(Object)
may not be called without
first calling forget()
.
Modifier and Type | Class and Description |
---|---|
static class |
WekaWrapper.Parameters
Simply a container for all of
WekaWrapper 's configurable parameters. |
Modifier and Type | Field and Description |
---|---|
protected String[] |
allowableValues
The label producing classifier's allowable values.
|
protected weka.core.FastVector |
attributeInfo
Information about the features this learner takes as input is parsed from an attribute string
and stored here.
|
protected String |
attributeString
A string encoding of the attributes used by this learner.
|
protected weka.classifiers.Classifier |
baseClassifier
Stores the instance of the WEKA classifier which we are training; default is
weka.classifiers.bayes.NaiveBayes . |
static String |
defaultAttributeString
Default for the
attributeString field. |
static weka.classifiers.Classifier |
defaultBaseClassifier
Default for the
baseClassifier field. |
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. |
candidates, encoding, extractor, labeler, labelLexicon, lcFilePath, lexFilePath, lexicon, lossFlag, predictions, readLexiconOnDemand
containingPackage, name
Constructor and Description |
---|
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,
String attributeString)
Redirecting constructor.
|
WekaWrapper(String n)
Empty constructor.
|
WekaWrapper(String n,
weka.classifiers.Classifier base)
Partial constructor; attribute information must be provided before any learning can occur.
|
WekaWrapper(String n,
weka.classifiers.Classifier base,
String attributeString)
Full Constructor.
|
WekaWrapper(String n,
String attributeString)
Default Constructor.
|
WekaWrapper(String n,
WekaWrapper.Parameters p)
Initializing constructor.
|
WekaWrapper(WekaWrapper.Parameters p)
Initializing constructor.
|
Modifier and Type | Method and Description |
---|---|
String[] |
allowableValues()
Returns the array of allowable values that a feature returned by this classifier may take.
|
FeatureVector |
classify(int[] exampleFeatures,
double[] exampleValues)
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. |
protected double[] |
getDistribution(int[] exampleFeatures,
double[] exampleValues)
Returns a discrete distribution of the classifier's prediction values.
|
String |
getOutputType()
This learner's output type is
"mixed%" . |
Learner.Parameters |
getParameters()
Retrieves the parameters that are set in this learner.
|
void |
initializeAttributes()
Takes
attributeString and initializes this wrapper's instances
collection to take those attributes. |
void |
learn(int[] exampleFeatures,
double[] exampleValues,
int[] exampleLabels,
double[] labelValues)
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. |
void |
read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Reads the binary representation of a learner with this object's run-time type, overwriting
any and all learned or manually specified parameters as well as the label lexicon but without
modifying the feature lexicon.
|
ScoreSet |
scores(int[] exampleFeatures,
double[] exampleValues)
Produces a set of scores indicating the degree to which each possible discrete classification
value is associated with the given example object.
|
void |
setLabeler(Classifier l)
Sets the labeler.
|
void |
setParameters(WekaWrapper.Parameters p)
Sets the values of parameters that control the behavior of this learning algorithm.
|
void |
write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
Writes the learned function's internal representation in binary form.
|
void |
write(PrintStream out)
Writes the settings of the classifier in use, and a string describing the classifier, if
available.
|
classify, classify, classify, classify, clone, countFeatures, createPrediction, createPrediction, demandLexicon, discreteValue, discreteValue, discreteValue, doneWithRound, emptyClone, featureValue, featureValue, featureValue, getCurrentLexicon, getExampleArray, getExampleArray, getExtractor, getLabeler, getLabelLexicon, getLexicon, getLexiconDiscardCounts, getLexiconLocation, getModelLocation, getPrunedLexiconSize, initialize, learn, learn, learn, learn, read, readLabelLexicon, readLearner, readLearner, readLearner, readLearner, readLearner, readLearner, readLexicon, readLexicon, readLexiconOnDemand, readLexiconOnDemand, readModel, readModel, readParameters, realValue, realValue, realValue, save, saveLexicon, saveModel, scores, scores, scoresAugmented, setCandidates, setEncoding, setExtractor, setLabelLexicon, setLexicon, setLexiconLocation, setLexiconLocation, setLossFlag, setModelLocation, setModelLocation, setParameters, setReadLexiconOnDemand, unclone, unsetLossFlag, write, writeLexicon, writeModel, writeParameters
classify, discreteValueArray, getCompositeChildren, getInputType, realValueArray, test, toString, valueIndexOf
public static final String defaultAttributeString
attributeString
field.public static final weka.classifiers.Classifier defaultBaseClassifier
baseClassifier
field.protected String attributeString
protected weka.classifiers.Classifier baseClassifier
weka.classifiers.bayes.NaiveBayes
.protected weka.classifiers.Classifier freshClassifier
protected weka.core.FastVector attributeInfo
Learner.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.protected String[] allowableValues
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, 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(String n)
weka.classifiers.bayes.NaiveBayes
. Attribute information must be provided before
any learning can occur.n
- The name of the classifier.public WekaWrapper(String n, weka.classifiers.Classifier base)
base
- The classifier to be used in this system.public WekaWrapper(String n, 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(String n, WekaWrapper.Parameters p)
WekaWrapper.Parameters
object.n
- The name of the classifier.p
- The settings of all parameters.public void setParameters(WekaWrapper.Parameters p)
p
- The parameters.public Learner.Parameters getParameters()
getParameters
in class Learner
public String getOutputType()
"mixed%"
.getOutputType
in class Classifier
public void initializeAttributes()
attributeString
and initializes this wrapper's instances
collection to take those attributes.public void setLabeler(Classifier l)
setLabeler
in class Learner
l
- A labeling classifier.public String[] allowableValues()
allowableValues
in class Classifier
public void learn(int[] exampleFeatures, double[] exampleValues, int[] exampleLabels, double[] labelValues)
Instance
object from this example and adds it to a set of
examples from which the classifier will be built once doneLearning()
is called.public FeatureVector classify(int[] exampleFeatures, double[] exampleValues)
protected double[] getDistribution(int[] exampleFeatures, double[] exampleValues)
exampleFeatures
- The example's array of feature indices.exampleValues
- The example's array of feature values.public void forget()
instances
collection of examples.public ScoreSet scores(int[] exampleFeatures, double[] exampleValues)
public void doneLearning()
buildClassifier(Instances)
method.doneLearning
in class Learner
public void write(PrintStream out)
public void write(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessOutputStream out)
public void read(edu.illinois.cs.cogcomp.core.datastructures.vectors.ExceptionlessInputStream in)
Copyright © 2016. All rights reserved.