Description

Logistic regression is a popular method to predict a categorical response.

Parameters

Name Description Type Required? Default Value
optimMethod optimization method String null
l1 the L1-regularized parameter. Double 0.0
l2 the L2-regularized parameter. Double 0.0
vectorCol Name of a vector column String null
withIntercept Whether has intercept or not, default is true Boolean true
maxIter Maximum iterations, The default value is 100 Integer 100
epsilon Convergence tolerance for iterative algorithms (>= 0), The default value is 1.0e-06 Double 1.0E-6
featureCols Names of the feature columns used for training in the input table String[] null
labelCol Name of the label column in the input table String
weightCol Name of the column indicating weight String null
vectorCol Name of a vector column String null
standardization Whether standardize training data or not, default is true Boolean true
predictionCol Column name of prediction. String
predictionDetailCol Column name of prediction result, it will include detailed info. String
reservedCols Names of the columns to be retained in the output table String[] null

Script Example

Script

  1. import numpy as np
  2. import pandas as pd
  3. data = np.array([
  4. [2, 1, 1],
  5. [3, 2, 1],
  6. [4, 3, 2],
  7. [2, 4, 1],
  8. [2, 2, 1],
  9. [4, 3, 2],
  10. [1, 2, 1],
  11. [5, 3, 2]])
  12. df = pd.DataFrame({"f0": data[:, 0],
  13. "f1": data[:, 1],
  14. "label": data[:, 2]})
  15. batchData = dataframeToOperator(df, schemaStr='f0 int, f1 int, label int', op_type='batch')
  16. colnames = ["f0","f1"]
  17. lr = LogisticRegression().setFeatureCols(colnames).setLabelCol("label").setPredictionCol("pred")
  18. model = lr.fit(batchData)
  19. model.transform(batchData).print()

Result

f0 f1 label pred
2 1 1 1
3 2 1 1
4 3 2 2
2 4 1 1
2 2 1 1
4 3 2 2
1 2 1 1
5 3 2 2