spark.logit {SparkR}R Documentation

Logistic Regression Model


Fits an logistic regression model against a SparkDataFrame. It supports "binomial": Binary logistic regression with pivoting; "multinomial": Multinomial logistic (softmax) regression without pivoting, similar to glmnet. Users can print, make predictions on the produced model and save the model to the input path.


spark.logit(data, formula, ...)

## S4 method for signature 'SparkDataFrame,formula'
spark.logit(data, formula, regParam = 0,
  elasticNetParam = 0, maxIter = 100, tol = 1e-06, family = "auto",
  standardization = TRUE, thresholds = 0.5, weightCol = NULL,
  aggregationDepth = 2)

## S4 method for signature 'LogisticRegressionModel'

## S4 method for signature 'LogisticRegressionModel'
predict(object, newData)

## S4 method for signature 'LogisticRegressionModel,character', path,
  overwrite = FALSE)



SparkDataFrame for training.


A symbolic description of the model to be fitted. Currently only a few formula operators are supported, including '~', '.', ':', '+', and '-'.


additional arguments passed to the method.


the regularization parameter.


the ElasticNet mixing parameter. For alpha = 0.0, the penalty is an L2 penalty. For alpha = 1.0, it is an L1 penalty. For 0.0 < alpha < 1.0, the penalty is a combination of L1 and L2. Default is 0.0 which is an L2 penalty.


maximum iteration number.


convergence tolerance of iterations.


the name of family which is a description of the label distribution to be used in the model. Supported options:

  • "auto": Automatically select the family based on the number of classes: If number of classes == 1 || number of classes == 2, set to "binomial". Else, set to "multinomial".

  • "binomial": Binary logistic regression with pivoting.

  • "multinomial": Multinomial logistic (softmax) regression without pivoting.


whether to standardize the training features before fitting the model. The coefficients of models will be always returned on the original scale, so it will be transparent for users. Note that with/without standardization, the models should be always converged to the same solution when no regularization is applied. Default is TRUE, same as glmnet.


in binary classification, in range [0, 1]. If the estimated probability of class label 1 is > threshold, then predict 1, else 0. A high threshold encourages the model to predict 0 more often; a low threshold encourages the model to predict 1 more often. Note: Setting this with threshold p is equivalent to setting thresholds c(1-p, p). In multiclass (or binary) classification to adjust the probability of predicting each class. Array must have length equal to the number of classes, with values > 0, excepting that at most one value may be 0. The class with largest value p/t is predicted, where p is the original probability of that class and t is the class's threshold.


The weight column name.


The depth for treeAggregate (greater than or equal to 2). If the dimensions of features or the number of partitions are large, this param could be adjusted to a larger size. This is an expert parameter. Default value should be good for most cases.


an LogisticRegressionModel fitted by spark.logit.


a SparkDataFrame for testing.


The directory where the model is saved.


Overwrites or not if the output path already exists. Default is FALSE which means throw exception if the output path exists.


spark.logit returns a fitted logistic regression model.

summary returns summary information of the fitted model, which is a list. The list includes coefficients (coefficients matrix of the fitted model).

predict returns the predicted values based on an LogisticRegressionModel.


spark.logit since 2.1.0

summary(LogisticRegressionModel) since 2.1.0

predict(LogisticRegressionModel) since 2.1.0, character) since 2.1.0


## Not run: 
##D sparkR.session()
##D # binary logistic regression
##D t <-
##D training <- createDataFrame(t)
##D model <- spark.logit(training, Survived ~ ., regParam = 0.5)
##D summary <- summary(model)
##D # fitted values on training data
##D fitted <- predict(model, training)
##D # save fitted model to input path
##D path <- "path/to/model"
##D, path)
##D # can also read back the saved model and predict
##D # Note that summary deos not work on loaded model
##D savedModel <-
##D summary(savedModel)
##D # multinomial logistic regression
##D model <- spark.logit(training, Class ~ ., regParam = 0.5)
##D summary <- summary(model)
## End(Not run)

[Package SparkR version 2.2.0 Index]