jsat.classifiers.linear
Class PassiveAggressive
- java.lang.Object
-
- jsat.classifiers.linear.PassiveAggressive
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, BinaryScoreClassifier, Classifier, UpdateableClassifier, Parameterized, Regressor, UpdateableRegressor, SimpleWeightVectorModel, SingleWeightVectorModel
public class PassiveAggressive extends java.lang.Object implements UpdateableClassifier, BinaryScoreClassifier, UpdateableRegressor, Parameterized, SingleWeightVectorModel
An implementations of the 3 versions of the Passive Aggressive algorithm for binary classification and regression. Its a type of online algorithm that performs the minimal update necessary to correct for a mistake.
See:
Crammer, K., Dekel, O., Keshet, J., Shalev-Shwartz, S.,&Singer, Y. (2006). Online passive-aggressive algorithms. Journal of Machine Learning Research, 7, 551–585.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classPassiveAggressive.ModeControls which version of the Passive Aggressive update is used
-
Constructor Summary
Constructors Constructor and Description PassiveAggressive()Creates a new Passive Aggressive learner that does 10 epochs and usesPassiveAggressive.Mode.PA1PassiveAggressive(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.PassiveAggressiveclone()doublegetBias()Returns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.doublegetBias(int index)Returns the bias term used with the weight vector for the given class index.doublegetC()Returns the aggressiveness parameterintgetEpochs()Returns the number of epochs used for trainingdoublegetEps()Returns the maximum acceptable difference in prediction and truthPassiveAggressive.ModegetMode()Returns which version of the PA update is usedVecgetRawWeight()Returns the only weight vector used for the modelVecgetRawWeight(int index)Returns the raw weight vector associated with the given class index.doublegetScore(DataPoint dp)Returns the numeric score for predicting a class of a given data point, where the sign of the value indicates which class the data point is predicted to belong to.static DistributionguessC(DataSet d)Guess the distribution to use for the regularization termCin PassiveAggressive.intnumWeightsVecs()Returns the number of weight vectors that can be returned.doubleregress(DataPoint data)voidsetC(double C)Set the aggressiveness parameter.voidsetEpochs(int epochs)Sets the number of whole iterations through the training set that will be performed for trainingvoidsetEps(double eps)Sets the range for numerical prediction.voidsetMode(PassiveAggressive.Mode mode)Sets which version of the PA update is used.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes)Prepares the classifier to begin learning from itsUpdateableRegressor.update(jsat.classifiers.DataPoint, double)method.voidsetUp(CategoricalData[] categoricalAttributes, int numericAttributes, CategoricalData predicting)Prepares the classifier to begin learning from itsUpdateableClassifier.update(jsat.classifiers.DataPoint, int)method.booleansupportsWeightedData()Indicates whether the model knows how to train using weighted data points.voidtrain(ClassificationDataSet dataSet)Trains the classifier and constructs a model for classification using the given data set.voidtrain(ClassificationDataSet dataSet, boolean parallel)Trains the classifier and constructs a model for classification using the given data set.voidtrain(RegressionDataSet dataSet)voidtrain(RegressionDataSet dataSet, boolean parallel)voidupdate(DataPoint dataPoint, double targetValue)Updates the classifier by giving it a new data point to learn from.voidupdate(DataPoint dataPoint, int targetClass)Updates the classifier by giving it a new data point to learn from.-
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
-
PassiveAggressive
public PassiveAggressive()
Creates a new Passive Aggressive learner that does 10 epochs and usesPassiveAggressive.Mode.PA1
-
PassiveAggressive
public PassiveAggressive(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
-
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
-
setEps
public void setEps(double eps)
Sets the range for numerical prediction. If it is within range of the given value, no error will be incurred.- Parameters:
eps- the maximum acceptable difference in prediction and truth
-
getEps
public double getEps()
Returns the maximum acceptable difference in prediction and truth- Returns:
- the maximum acceptable difference in prediction and truth
-
setEpochs
public void setEpochs(int epochs)
Sets the number of whole iterations through the training set that will be performed for training- Parameters:
epochs- the number of whole iterations through the data set
-
getEpochs
public int getEpochs()
Returns the number of epochs used for training- Returns:
- the number of epochs used for training
-
getRawWeight
public Vec getRawWeight()
Description copied from interface:SingleWeightVectorModelReturns the only weight vector used for the model- Specified by:
getRawWeightin interfaceSingleWeightVectorModel- Returns:
- the only weight vector used for the model
-
getBias
public double getBias()
Description copied from interface:SingleWeightVectorModelReturns the bias term used for the model, or 0 of the model does not support or was not trained with a bias term.- Specified by:
getBiasin interfaceSingleWeightVectorModel- Returns:
- the bias term for the model
-
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.
-
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.
-
getScore
public double getScore(DataPoint dp)
Description copied from interface:BinaryScoreClassifierReturns the numeric score for predicting a class of a given data point, where the sign of the value indicates which class the data point is predicted to belong to.- Specified by:
getScorein interfaceBinaryScoreClassifier- Parameters:
dp- the data point to predict the class label of- Returns:
- the score for the given data point
-
train
public void train(ClassificationDataSet dataSet, boolean parallel)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set. If the training method knows how, it will used the threadPool to conduct training in parallel. This method will block until the training has completed.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train onparallel-trueif multiple threads should be used to train the model.falseif it should be done in a single threaded manner.
-
train
public void train(ClassificationDataSet dataSet)
Description copied from interface:ClassifierTrains the classifier and constructs a model for classification using the given data set.- Specified by:
trainin interfaceClassifier- Parameters:
dataSet- the data set to train on
-
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- Specified by:
supportsWeightedDatain interfaceRegressor- Returns:
- true if the model supports weighted data, false otherwise
-
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
-
setUp
public void setUp(CategoricalData[] categoricalAttributes, int numericAttributes)
Description copied from interface:UpdateableRegressorPrepares the classifier to begin learning from itsUpdateableRegressor.update(jsat.classifiers.DataPoint, double)method.- Specified by:
setUpin interfaceUpdateableRegressor- 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 point
-
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
-
update
public void update(DataPoint dataPoint, double targetValue)
Description copied from interface:UpdateableRegressorUpdates the classifier by giving it a new data point to learn from.- Specified by:
updatein interfaceUpdateableRegressor- Parameters:
dataPoint- the data point to learntargetValue- the target value of the data point
-
train
public void train(RegressionDataSet dataSet, boolean parallel)
-
train
public void train(RegressionDataSet dataSet)
-
clone
public PassiveAggressive clone()
- Specified by:
clonein interfaceBinaryScoreClassifier- Specified by:
clonein interfaceClassifier- Specified by:
clonein interfaceUpdateableClassifier- Specified by:
clonein interfaceRegressor- Specified by:
clonein interfaceUpdateableRegressor- Overrides:
clonein classjava.lang.Object
-
guessC
public static Distribution guessC(DataSet d)
Guess the distribution to use for the regularization termCin 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