Package smile.classification
Class SparseLogisticRegression
java.lang.Object
smile.classification.AbstractClassifier<smile.util.SparseArray>
smile.classification.SparseLogisticRegression
- All Implemented Interfaces:
Serializable,ToDoubleFunction<smile.util.SparseArray>,ToIntFunction<smile.util.SparseArray>,Classifier<smile.util.SparseArray>
- Direct Known Subclasses:
SparseLogisticRegression.Binomial,SparseLogisticRegression.Multinomial
Logistic regression on sparse data.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBinomial logistic regression.static classMultinomial logistic regression.Nested classes/interfaces inherited from interface smile.classification.Classifier
Classifier.Trainer<T,M extends Classifier<T>> -
Field Summary
Fields inherited from class smile.classification.AbstractClassifier
classes -
Constructor Summary
ConstructorsConstructorDescriptionSparseLogisticRegression(int p, double L, double lambda, smile.util.IntSet labels) Constructor. -
Method Summary
Modifier and TypeMethodDescriptiondoubleAIC()Returns the AIC score.binomial(smile.data.SparseDataset x, int[] y) Fits binomial logistic regression.binomial(smile.data.SparseDataset x, int[] y, double lambda, double tol, int maxIter) Fits binomial logistic regression.binomial(smile.data.SparseDataset x, int[] y, Properties params) Fits binomial logistic regression.static SparseLogisticRegressionfit(smile.data.SparseDataset x, int[] y) Fits logistic regression.static SparseLogisticRegressionfit(smile.data.SparseDataset x, int[] y, double lambda, double tol, int maxIter) Fits logistic regression.static SparseLogisticRegressionfit(smile.data.SparseDataset x, int[] y, Properties params) Fits logistic regression.doubleReturns the learning rate of stochastic gradient descent.doubleReturns the log-likelihood of model.multinomial(smile.data.SparseDataset x, int[] y) Fits multinomial logistic regression.multinomial(smile.data.SparseDataset x, int[] y, double lambda, double tol, int maxIter) Fits multinomial logistic regression.multinomial(smile.data.SparseDataset x, int[] y, Properties params) Fits multinomial logistic regression.booleanonline()Returns true if this is an online learner.voidsetLearningRate(double rate) Sets the learning rate of stochastic gradient descent.booleansoft()Returns true if this is a soft classifier that can estimate the posteriori probabilities of classification.Methods inherited from class smile.classification.AbstractClassifier
classes, numClassesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface smile.classification.Classifier
applyAsDouble, applyAsInt, predict, predict, predict, predict, predict, predict, predict, predict, score, update, update, update
-
Constructor Details
-
SparseLogisticRegression
public SparseLogisticRegression(int p, double L, double lambda, smile.util.IntSet labels) Constructor.- Parameters:
p- the dimension of input data.L- the log-likelihood of learned model.lambda-lambda > 0gives a "regularized" estimate of linear weights which often has superior generalization performance, especially when the dimensionality is high.labels- the class label encoder.
-
-
Method Details
-
binomial
Fits binomial logistic regression.- Parameters:
x- training samples.y- training labels.- Returns:
- the model.
-
binomial
public static SparseLogisticRegression.Binomial binomial(smile.data.SparseDataset x, int[] y, Properties params) Fits binomial logistic regression.- Parameters:
x- training samples.y- training labels.params- the hyper-parameters.- Returns:
- the model.
-
binomial
public static SparseLogisticRegression.Binomial binomial(smile.data.SparseDataset x, int[] y, double lambda, double tol, int maxIter) Fits binomial logistic regression.- Parameters:
x- training samples.y- training labels.lambda-lambda > 0gives a "regularized" estimate of linear weights which often has superior generalization performance, especially when the dimensionality is high.tol- the tolerance for stopping iterations.maxIter- the maximum number of iterations.- Returns:
- the model.
-
multinomial
Fits multinomial logistic regression.- Parameters:
x- training samples.y- training labels.- Returns:
- the model.
-
multinomial
public static SparseLogisticRegression.Multinomial multinomial(smile.data.SparseDataset x, int[] y, Properties params) Fits multinomial logistic regression.- Parameters:
x- training samples.y- training labels.params- the hyper-parameters.- Returns:
- the model.
-
multinomial
public static SparseLogisticRegression.Multinomial multinomial(smile.data.SparseDataset x, int[] y, double lambda, double tol, int maxIter) Fits multinomial logistic regression.- Parameters:
x- training samples.y- training labels.lambda-lambda > 0gives a "regularized" estimate of linear weights which often has superior generalization performance, especially when the dimensionality is high.tol- the tolerance for stopping iterations.maxIter- the maximum number of iterations.- Returns:
- the model.
-
fit
Fits logistic regression.- Parameters:
x- training samples.y- training labels.- Returns:
- the model.
-
fit
Fits logistic regression.- Parameters:
x- training samples.y- training labels.params- the hyper-parameters.- Returns:
- the model.
-
fit
public static SparseLogisticRegression fit(smile.data.SparseDataset x, int[] y, double lambda, double tol, int maxIter) Fits logistic regression.- Parameters:
x- training samples.y- training labels.lambda-lambda > 0gives a "regularized" estimate of linear weights which often has superior generalization performance, especially when the dimensionality is high.tol- the tolerance for stopping iterations.maxIter- the maximum number of iterations.- Returns:
- the model.
-
soft
public boolean soft()Description copied from interface:ClassifierReturns true if this is a soft classifier that can estimate the posteriori probabilities of classification.- Returns:
- true if soft classifier.
-
online
public boolean online()Description copied from interface:ClassifierReturns true if this is an online learner.- Returns:
- true if online learner.
-
setLearningRate
public void setLearningRate(double rate) Sets the learning rate of stochastic gradient descent. It is a good practice to adapt the learning rate for different data sizes. For example, it is typical to set the learning rate to eta/n, where eta is in [0.1, 0.3] and n is the size of the training data.- Parameters:
rate- the learning rate.
-
getLearningRate
public double getLearningRate()Returns the learning rate of stochastic gradient descent.- Returns:
- the learning rate of stochastic gradient descent.
-
loglikelihood
public double loglikelihood()Returns the log-likelihood of model.- Returns:
- the log-likelihood of model.
-
AIC
public double AIC()Returns the AIC score.- Returns:
- the AIC score.
-