Package weka.classifiers.functions
Class SPegasos
- java.lang.Object
-
- weka.classifiers.Classifier
-
- weka.classifiers.functions.SPegasos
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,UpdateableClassifier
,CapabilitiesHandler
,OptionHandler
,RevisionHandler
,TechnicalInformationHandler
public class SPegasos extends Classifier implements TechnicalInformationHandler, UpdateableClassifier, OptionHandler
Implements the stochastic variant of the Pegasos (Primal Estimated sub-GrAdient SOlver for SVM) method of Shalev-Shwartz et al. (2007). This implementation globally replaces all missing values and transforms nominal attributes into binary ones. It also normalizes all attributes, so the coefficients in the output are based on the normalized data. For more information, see
S. Shalev-Shwartz, Y. Singer, N. Srebro: Pegasos: Primal Estimated sub-GrAdient SOlver for SVM. In: 24th International Conference on MachineLearning, 807-814, 2007. BibTeX:@inproceedings{Shalev-Shwartz2007, author = {S. Shalev-Shwartz and Y. Singer and N. Srebro}, booktitle = {24th International Conference on MachineLearning}, pages = {807-814}, title = {Pegasos: Primal Estimated sub-GrAdient SOlver for SVM}, year = {2007} }
Valid options are:-L <double> The lambda regularization constant (default = 0.0001)
-E <integer> The number of epochs to perform (batch learning only, default = 500)
-N Don't normalize the data
-M Don't replace missing values
- Version:
- $Revision: 6580 $
- Author:
- Mark Hall (mhall{[at]}pentaho{[dot]}com)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static Tag[]
TAGS_SELECTION
Loss functions to choose from
-
Constructor Summary
Constructors Constructor Description SPegasos()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
buildClassifier(Instances data)
Method for building the classifier.double[]
distributionForInstance(Instance inst)
Computes the distribution for a given instancejava.lang.String
dontNormalizeTipText()
Returns the tip text for this propertyjava.lang.String
dontReplaceMissingTipText()
Returns the tip text for this propertyjava.lang.String
epochsTipText()
Returns the tip text for this propertyCapabilities
getCapabilities()
Returns default capabilities of the classifier.boolean
getDontNormalize()
Get whether normalization has been turned off.boolean
getDontReplaceMissing()
Get whether global replacement of missing values has been disabled.int
getEpochs()
Get current number of epochsdouble
getLambda()
Get the current value of lambdaSelectedTag
getLossFunction()
Get the current loss function.java.lang.String[]
getOptions()
Gets the current settings of the classifier.java.lang.String
getRevision()
Returns the revision string.TechnicalInformation
getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.java.lang.String
globalInfo()
Returns a string describing classifierjava.lang.String
lambdaTipText()
Returns the tip text for this propertyjava.util.Enumeration<Option>
listOptions()
Returns an enumeration describing the available options.java.lang.String
lossFunctionTipText()
Returns the tip text for this propertystatic void
main(java.lang.String[] args)
Main method for testing this class.void
reset()
Reset the classifier.void
setDontNormalize(boolean m)
Turn normalization off/on.void
setDontReplaceMissing(boolean m)
Turn global replacement of missing values off/on.void
setEpochs(int e)
Set the number of epochs to usevoid
setLambda(double lambda)
Set the value of lambda to usevoid
setLossFunction(SelectedTag function)
Set the loss function to use.void
setOptions(java.lang.String[] options)
Parses a given list of options.java.lang.String
toString()
Prints out the classifier.void
updateClassifier(Instance instance)
Updates the classifier with the given instance.-
Methods inherited from class weka.classifiers.Classifier
classifyInstance, debugTipText, forName, getDebug, makeCopies, makeCopy, setDebug
-
-
-
-
Field Detail
-
TAGS_SELECTION
public static final Tag[] TAGS_SELECTION
Loss functions to choose from
-
-
Method Detail
-
getCapabilities
public Capabilities getCapabilities()
Returns default capabilities of the classifier.- Specified by:
getCapabilities
in interfaceCapabilitiesHandler
- Overrides:
getCapabilities
in classClassifier
- Returns:
- the capabilities of this classifier
- See Also:
Capabilities
-
lambdaTipText
public java.lang.String lambdaTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setLambda
public void setLambda(double lambda)
Set the value of lambda to use- Parameters:
lambda
- the value of lambda to use
-
getLambda
public double getLambda()
Get the current value of lambda- Returns:
- the current value of lambda
-
epochsTipText
public java.lang.String epochsTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setEpochs
public void setEpochs(int e)
Set the number of epochs to use- Parameters:
e
- the number of epochs to use
-
getEpochs
public int getEpochs()
Get current number of epochs- Returns:
- the current number of epochs
-
setDontNormalize
public void setDontNormalize(boolean m)
Turn normalization off/on.- Parameters:
m
- true if normalization is to be disabled.
-
getDontNormalize
public boolean getDontNormalize()
Get whether normalization has been turned off.- Returns:
- true if normalization has been disabled.
-
dontNormalizeTipText
public java.lang.String dontNormalizeTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setDontReplaceMissing
public void setDontReplaceMissing(boolean m)
Turn global replacement of missing values off/on. If turned off, then missing values are effectively ignored.- Parameters:
m
- true if global replacement of missing values is to be turned off.
-
getDontReplaceMissing
public boolean getDontReplaceMissing()
Get whether global replacement of missing values has been disabled.- Returns:
- true if global replacement of missing values has been turned off
-
dontReplaceMissingTipText
public java.lang.String dontReplaceMissingTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
setLossFunction
public void setLossFunction(SelectedTag function)
Set the loss function to use.- Parameters:
function
- the loss function to use.
-
getLossFunction
public SelectedTag getLossFunction()
Get the current loss function.- Returns:
- the current loss function.
-
lossFunctionTipText
public java.lang.String lossFunctionTipText()
Returns the tip text for this property- Returns:
- tip text for this property suitable for displaying in the explorer/experimenter gui
-
listOptions
public java.util.Enumeration<Option> listOptions()
Returns an enumeration describing the available options.- Specified by:
listOptions
in interfaceOptionHandler
- Overrides:
listOptions
in classClassifier
- Returns:
- an enumeration of all the available options.
-
setOptions
public void setOptions(java.lang.String[] options) throws java.lang.Exception
Parses a given list of options. Valid options are:-L <double> The lambda regularization constant (default = 0.0001)
-E <integer> The number of epochs to perform (batch learning only, default = 500)
-N Don't normalize the data
-M Don't replace missing values
- Specified by:
setOptions
in interfaceOptionHandler
- Overrides:
setOptions
in classClassifier
- Parameters:
options
- the list of options as an array of strings- Throws:
java.lang.Exception
- if an option is not supported
-
getOptions
public java.lang.String[] getOptions()
Gets the current settings of the classifier.- Specified by:
getOptions
in interfaceOptionHandler
- Overrides:
getOptions
in classClassifier
- Returns:
- an array of strings suitable for passing to setOptions
-
globalInfo
public java.lang.String globalInfo()
Returns a string describing classifier- Returns:
- a description suitable for displaying in the explorer/experimenter gui
-
getTechnicalInformation
public TechnicalInformation getTechnicalInformation()
Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.- Specified by:
getTechnicalInformation
in interfaceTechnicalInformationHandler
- Returns:
- the technical information about this class
-
reset
public void reset()
Reset the classifier.
-
buildClassifier
public void buildClassifier(Instances data) throws java.lang.Exception
Method for building the classifier.- Specified by:
buildClassifier
in classClassifier
- Parameters:
data
- the set of training instances.- Throws:
java.lang.Exception
- if the classifier can't be built successfully.
-
updateClassifier
public void updateClassifier(Instance instance) throws java.lang.Exception
Updates the classifier with the given instance.- Specified by:
updateClassifier
in interfaceUpdateableClassifier
- Parameters:
instance
- the new training instance to include in the model- Throws:
java.lang.Exception
- if the instance could not be incorporated in the model.
-
distributionForInstance
public double[] distributionForInstance(Instance inst) throws java.lang.Exception
Computes the distribution for a given instance- Overrides:
distributionForInstance
in classClassifier
- Parameters:
instance
- the instance for which distribution is computed- Returns:
- the distribution
- Throws:
java.lang.Exception
- if the distribution can't be computed successfully
-
toString
public java.lang.String toString()
Prints out the classifier.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a description of the classifier as a string
-
getRevision
public java.lang.String getRevision()
Returns the revision string.- Specified by:
getRevision
in interfaceRevisionHandler
- Overrides:
getRevision
in classClassifier
- Returns:
- the revision
-
main
public static void main(java.lang.String[] args)
Main method for testing this class.
-
-