jsat.classifiers.linear
Class SPA
- java.lang.Object
-
- jsat.classifiers.BaseUpdateableClassifier
-
- jsat.classifiers.linear.SPA
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, UpdateableClassifier, Parameterized, SimpleWeightVectorModel
public class SPA extends BaseUpdateableClassifier implements Parameterized, SimpleWeightVectorModel
Support class Passive Aggressive (SPA) is a multi class generalization ofPassiveAggressive. It works in the same philosophy, and can obtain better multi class accuracy then PA used with a meta learner.
SPA is more sensitive to small values for theaggressiveness parameter.
If working with a binary classification problem, SPA reduces to PA, and the original PA implementation should be used instead.
By default, thebiast termis not used.
See:
Matsushima, S., Shimizu, N., Yoshida, K., Ninomiya, T.,&Nakagawa, H. (2010). Exact Passive-Aggressive Algorithm for Multiclass Classification Using Support Class. SIAM International Conference on Data Mining - SDM (pp. 303–314). Retrieved from here- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SPA()Creates a new Passive Aggressive learner that does 10 epochs and uses PA2.SPA(int epochs, PassiveAggressive.Mode mode)Creates a new Passive Aggressive learner
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description CategoricalResultsclassify(DataPoint data)Performs classification on the given data point.SPAclone()doublegetBias(int index)Returns the bias term used with the weight vector for the given class index.doublegetC()Returns the aggressiveness parameterPassiveAggressive.ModegetMode()Returns which version of the PA update is usedVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.static DistributionguessC(DataSet d)Guess the distribution to use for the regularization termCin Support PassiveAggressive.booleanisUseBias()Returns true if an implicit bias term will be added, false otherwiseintnumWeightsVecs()Returns the number of weight vectors that can be returned.voidsetC(double C)Set the aggressiveness parameter.voidsetMode(PassiveAggressive.Mode mode)Sets which version of the PA update is used.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)Prepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.voidsetUseBias(boolean useBias)Sets whether or not the implementation will use an implicit bias term appended to the inputs or not.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidupdate(DataPoint dataPoint, int targetClass)Updates the classifier by giving it a new data point to learn from.-
Methods inherited from class jsat.classifiers.BaseUpdateableClassifier
getEpochs, setEpochs, train, train, trainEpochs
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jsat.parameters.Parameterized
getParameter, getParameters
-
-
-
-
Constructor Detail
-
SPA
public SPA()
Creates a new Passive Aggressive learner that does 10 epochs and uses PA2.
-
SPA
public SPA(int epochs, PassiveAggressive.Mode mode)Creates a new Passive Aggressive learner- Parameters:
epochs- the number of training epochs to use during batch trainingmode- which version of the update to perform
-
-
Method Detail
-
setUseBias
public void setUseBias(boolean useBias)
Sets whether or not the implementation will use an implicit bias term appended to the inputs or not.- Parameters:
useBias-trueto add an implicit bias term,falseto use the data as given
-
isUseBias
public boolean isUseBias()
Returns true if an implicit bias term will be added, false otherwise- Returns:
- true if an implicit bias term will be added, false otherwise
-
setC
public void setC(double C)
Set the aggressiveness parameter. Increasing the value of this parameter increases the aggressiveness of the algorithm. It must be a positive value. This parameter essentially performs a type of regularization on the updates
An infinitely large value is equivalent to being completely aggressive, and is performed when the mode is set toPassiveAggressive.Mode.PA.- Parameters:
C- the positive aggressiveness parameter
-
getC
public double getC()
Returns the aggressiveness parameter- Returns:
- the aggressiveness parameter
-
setMode
public void setMode(PassiveAggressive.Mode mode)
Sets which version of the PA update is used.- Parameters:
mode- which PA update style to perform
-
getMode
public PassiveAggressive.Mode getMode()
Returns which version of the PA update is used- Returns:
- which PA update style is used
-
getRawWeight
public Vec getRawWeight(int index)
Description copied from interface:SimpleWeightVectorModelReturns the raw weight vector associated with the given class index. If the given class is an implicit zero vector, aConstantVectorobject may be returned.
Do not alter the returned weight vector, as it will change the model's values.
If a regression problem, onlyindex = 0should be used- Specified by:
getRawWeightin interfaceSimpleWeightVectorModel- Parameters:
index- the class index to get the weight vector for- Returns:
- the weight vector used for the specified class
-
getBias
public double getBias(int index)
Description copied from interface:SimpleWeightVectorModelReturns the bias term used with the weight vector for the given class index. If the model does not support or was not trained with bias weights,0will be returned.
If a regression problem, onlyindex = 0should be used- Specified by:
getBiasin interfaceSimpleWeightVectorModel- Parameters:
index- the class index to get the weight vector for- Returns:
- the bias term for the specified class
-
numWeightsVecs
public int numWeightsVecs()
Description copied from interface:SimpleWeightVectorModelReturns the number of weight vectors that can be returned. For binary classification problems the value may be 1 if only a single weight vector's sign is used to determine the class. For multi-class problems, the weight vector count includes the implicit zero vector (if one is being used).- Specified by:
numWeightsVecsin interfaceSimpleWeightVectorModel- Returns:
- the number of weight vectors for which
SimpleWeightVectorModel.getRawWeight(int)can be called.
-
clone
public SPA clone()
- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceUpdateableClassifier- Specified by:
clonein classBaseUpdateableClassifier
-
setUp
public void setUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)
Description copied from interface:UpdateableClassifierPrepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.- Specified by:
setUpin interfaceUpdateableClassifier- Parameters:
categoricalAttributes- an array containing the categorical attributes that will be in each data pointnumericAttributes- the number of numeric attributes that will be in each data pointpredicting- the information for the target class that will be predicted
-
update
public void update(DataPoint dataPoint, int targetClass)
Description copied from interface:UpdateableClassifierUpdates the classifier by giving it a new data point to learn from.- Specified by:
updatein interfaceUpdateableClassifier- Parameters:
dataPoint- the data point to learntargetClass- the target class of the data point
-
classify
public CategoricalResults classify(DataPoint data)
Description copied from interface:ClassifierPerforms classification on the given data point.- Specified by:
classifyin interfaceClassifier- Parameters:
data- the data point to classify- Returns:
- the results of the classification.
-
supportsWeightedData
public boolean supportsWeightedData()
Description copied from interface:ClassifierIndicates whether the model knows how to train using weighted data points. If it does, the model will train assuming the weights. The values returned by this method may change depending on the parameters set for the model.- Specified by:
supportsWeightedDatain interfaceClassifier- Returns:
- true if the model supports weighted data, false otherwise
-
guessC
public static Distribution guessC(DataSet d)
Guess the distribution to use for the regularization termCin Support PassiveAggressive.- Parameters:
d- the data set to get the guess for- Returns:
- the guess for the C parameter
-
-
DataMelt 3.0 © DataMelt by jWork.ORG