jsat.classifiers.linear.kernelized
Class CSKLR
- java.lang.Object
-
- jsat.classifiers.BaseUpdateableClassifier
-
- jsat.classifiers.linear.kernelized.CSKLR
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable, Classifier, UpdateableClassifier, Parameterized
public class CSKLR extends BaseUpdateableClassifier implements Parameterized
An implementation of Conservative Stochastic Kernel Logistic Regression. This is an online algorithm that obtains sparse solutions by conservatively rejecting updates based on a binomial distribution of the error on each update.
This algorithm works best on data sets with a very high number of samples where a high accuracy is obtainable using a kernel model. It is often the case that this model produces accurate results, but has a low confidence due to the conservative updating. This can be counteracted by having a very large number of features, but that often increases the size of the model.
It is important to read the documentation and test some different values for thelearning rateandgammavariables. They behave different compared to many algorithms.
It is possible to obtain a more confident model and a slightly larger model by using several epochs. Instead of using this class, thebatch versionof this algorithm should be used instead.
See paper:
Zhang, L., Jin, R., Chen, C., Bu, J.,&He, X. (2012). Efficient Online Learning for Large-Scale Sparse Kernel Logistic Regression. Twenty-Sixth AAAI Conference on Artificial Intelligence (pp. 1219–1225). Retrieved from here- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classCSKLR.UpdateModeControls when updates are performed on the model.
-
Constructor Summary
Constructors Constructor and Description CSKLR(double eta, KernelTrick k, double R, CSKLR.UpdateMode mode)Creates a new CSKLR object
-
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.CSKLRclone()doublegetEta()Returns the learning rate to usedoublegetGamma()Returns the gamma sparsity parameter valueKernelTrickgetKernel()Returns the kernel trick in useCSKLR.UpdateModegetMode()Returns the update mode in usedoublegetR()Returns the maximal norm of the algorithmstatic DistributionguessR(DataSet d)Guesses the distribution to use for the R parametervoidsetEta(double eta)Sets the learning rate to use for the algorithm.voidsetGamma(double gamma)Sets the gamma value to use.voidsetKernel(KernelTrick k)Set which kernel trick to usevoidsetMode(CSKLR.UpdateMode mode)Sets what update mode should be used.voidsetR(double R)Sets the maximal margin norm value for the algorithm.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.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
-
CSKLR
public CSKLR(double eta, KernelTrick k, double R, CSKLR.UpdateMode mode)Creates a new CSKLR object- Parameters:
eta- the learning rate to usek- the kernel trick to useR- the maximal norm of the surfacemode- the mode to use
-
-
Method Detail
-
guessR
public static Distribution guessR(DataSet d)
Guesses the distribution to use for the R parameter- Parameters:
d- the dataset to get the guess for- Returns:
- the guess for the R parameter
- See Also:
setR(double)
-
setEta
public void setEta(double eta)
Sets the learning rate to use for the algorithm. Unlike many other stochastic algorithms, the learning rate for CSKLR should be large, often in the range of (0.5, 1) - and can even be larger than 1 at times. If the learning rate is too low, it may be difficult to get strong confidence results from the algorithm.- Parameters:
eta- the positive learning rate to use
-
getEta
public double getEta()
Returns the learning rate to use- Returns:
- the learning rate to use
-
setR
public void setR(double R)
Sets the maximal margin norm value for the algorithm. When the norm is exceeded, the coefficients will be rescaled to fit in the norm. If the maximal norm is too small (less than 5), it may be difficult to get strong confidence results from the algorithm.
A good range of values suggested by the original paper is 10x ∀ x ∈ {0, 1, 2, 3, 4, 5}- Parameters:
R-
-
getR
public double getR()
Returns the maximal norm of the algorithm- Returns:
- the maximal norm of the algorithm
-
setMode
public void setMode(CSKLR.UpdateMode mode)
Sets what update mode should be used. The update mode controls the sparsity of the mode, and the behavior ofsetGamma(double)- Parameters:
mode- the update mode to use
-
getMode
public CSKLR.UpdateMode getMode()
Returns the update mode in use- Returns:
- the update mode in use
-
setGamma
public void setGamma(double gamma)
Sets the gamma value to use. This value, depending on whichCSKLR.UpdateModeis used, controls the sparsity of the model.- Parameters:
gamma- the gamma parameter, which is at least always positive
-
getGamma
public double getGamma()
Returns the gamma sparsity parameter value- Returns:
- the gamma sparsity parameter value
-
setKernel
public void setKernel(KernelTrick k)
Set which kernel trick to use- Parameters:
k- the kernel to use
-
getKernel
public KernelTrick getKernel()
Returns the kernel trick in use- Returns:
- the kernel trick in use
-
clone
public CSKLR 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
-
-
DataMelt 3.0 © DataMelt by jWork.ORG