org.apache.spark.mllib.classification
Class LogisticRegressionWithSGD

Object
  extended by org.apache.spark.mllib.regression.GeneralizedLinearAlgorithm<LogisticRegressionModel>
      extended by org.apache.spark.mllib.classification.LogisticRegressionWithSGD
All Implemented Interfaces:
java.io.Serializable, Logging

public class LogisticRegressionWithSGD
extends GeneralizedLinearAlgorithm<LogisticRegressionModel>
implements scala.Serializable

Train a classification model for Binary Logistic Regression using Stochastic Gradient Descent. By default L2 regularization is used, which can be changed via LogisticRegressionWithSGD.optimizer. NOTE: Labels used in Logistic Regression should be {0, 1, ..., k - 1} for k classes multi-label classification problem. Using LogisticRegressionWithLBFGS is recommended over this.

See Also:
Serialized Form

Constructor Summary
LogisticRegressionWithSGD()
          Construct a LogisticRegression object with default parameters: {stepSize: 1.0, numIterations: 100, regParm: 0.01, miniBatchFraction: 1.0}.
 
Method Summary
 GradientDescent optimizer()
          The optimizer to solve the problem.
static LogisticRegressionModel train(RDD<LabeledPoint> input, int numIterations)
          Train a logistic regression model given an RDD of (label, features) pairs.
static LogisticRegressionModel train(RDD<LabeledPoint> input, int numIterations, double stepSize)
          Train a logistic regression model given an RDD of (label, features) pairs.
static LogisticRegressionModel train(RDD<LabeledPoint> input, int numIterations, double stepSize, double miniBatchFraction)
          Train a logistic regression model given an RDD of (label, features) pairs.
static LogisticRegressionModel train(RDD<LabeledPoint> input, int numIterations, double stepSize, double miniBatchFraction, Vector initialWeights)
          Train a logistic regression model given an RDD of (label, features) pairs.
 
Methods inherited from class org.apache.spark.mllib.regression.GeneralizedLinearAlgorithm
getNumFeatures, isAddIntercept, run, run, setIntercept, setValidateData
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.spark.Logging
initializeIfNecessary, initializeLogging, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
 

Constructor Detail

LogisticRegressionWithSGD

public LogisticRegressionWithSGD()
Construct a LogisticRegression object with default parameters: {stepSize: 1.0, numIterations: 100, regParm: 0.01, miniBatchFraction: 1.0}.

Method Detail

train

public static LogisticRegressionModel train(RDD<LabeledPoint> input,
                                            int numIterations,
                                            double stepSize,
                                            double miniBatchFraction,
                                            Vector initialWeights)
Train a logistic regression model given an RDD of (label, features) pairs. We run a fixed number of iterations of gradient descent using the specified step size. Each iteration uses miniBatchFraction fraction of the data to calculate the gradient. The weights used in gradient descent are initialized using the initial weights provided. NOTE: Labels used in Logistic Regression should be {0, 1}

Parameters:
input - RDD of (label, array of features) pairs.
numIterations - Number of iterations of gradient descent to run.
stepSize - Step size to be used for each iteration of gradient descent.
miniBatchFraction - Fraction of data to be used per iteration.
initialWeights - Initial set of weights to be used. Array should be equal in size to the number of features in the data.
Returns:
(undocumented)

train

public static LogisticRegressionModel train(RDD<LabeledPoint> input,
                                            int numIterations,
                                            double stepSize,
                                            double miniBatchFraction)
Train a logistic regression model given an RDD of (label, features) pairs. We run a fixed number of iterations of gradient descent using the specified step size. Each iteration uses miniBatchFraction fraction of the data to calculate the gradient. NOTE: Labels used in Logistic Regression should be {0, 1}

Parameters:
input - RDD of (label, array of features) pairs.
numIterations - Number of iterations of gradient descent to run.
stepSize - Step size to be used for each iteration of gradient descent.

miniBatchFraction - Fraction of data to be used per iteration.
Returns:
(undocumented)

train

public static LogisticRegressionModel train(RDD<LabeledPoint> input,
                                            int numIterations,
                                            double stepSize)
Train a logistic regression model given an RDD of (label, features) pairs. We run a fixed number of iterations of gradient descent using the specified step size. We use the entire data set to update the gradient in each iteration. NOTE: Labels used in Logistic Regression should be {0, 1}

Parameters:
input - RDD of (label, array of features) pairs.
stepSize - Step size to be used for each iteration of Gradient Descent.

numIterations - Number of iterations of gradient descent to run.
Returns:
a LogisticRegressionModel which has the weights and offset from training.

train

public static LogisticRegressionModel train(RDD<LabeledPoint> input,
                                            int numIterations)
Train a logistic regression model given an RDD of (label, features) pairs. We run a fixed number of iterations of gradient descent using a step size of 1.0. We use the entire data set to update the gradient in each iteration. NOTE: Labels used in Logistic Regression should be {0, 1}

Parameters:
input - RDD of (label, array of features) pairs.
numIterations - Number of iterations of gradient descent to run.
Returns:
a LogisticRegressionModel which has the weights and offset from training.

optimizer

public GradientDescent optimizer()
Description copied from class: GeneralizedLinearAlgorithm
The optimizer to solve the problem.

Specified by:
optimizer in class GeneralizedLinearAlgorithm<LogisticRegressionModel>