Class LogisticRegression
Object
org.apache.spark.ml.PipelineStage
org.apache.spark.ml.Estimator<M>
org.apache.spark.ml.Predictor<FeaturesType,E,M>
org.apache.spark.ml.classification.Classifier<FeaturesType,E,M>
org.apache.spark.ml.classification.ProbabilisticClassifier<Vector,LogisticRegression,LogisticRegressionModel>
org.apache.spark.ml.classification.LogisticRegression
- All Implemented Interfaces:
Serializable,org.apache.spark.internal.Logging,org.apache.spark.ml.classification.ClassifierParams,org.apache.spark.ml.classification.LogisticRegressionParams,org.apache.spark.ml.classification.ProbabilisticClassifierParams,Params,HasAggregationDepth,HasElasticNetParam,HasFeaturesCol,HasFitIntercept,HasLabelCol,HasMaxBlockSizeInMB,HasMaxIter,HasPredictionCol,HasProbabilityCol,HasRawPredictionCol,HasRegParam,HasStandardization,HasThreshold,HasThresholds,HasTol,HasWeightCol,org.apache.spark.ml.PredictorParams,DefaultParamsWritable,Identifiable,MLWritable
public class LogisticRegression
extends ProbabilisticClassifier<Vector,LogisticRegression,LogisticRegressionModel>
implements org.apache.spark.ml.classification.LogisticRegressionParams, DefaultParamsWritable, org.apache.spark.internal.Logging
Logistic regression. Supports:
- Multinomial logistic (softmax) regression.
- Binomial logistic regression.
This class supports fitting traditional logistic regression model by LBFGS/OWLQN and bound (box) constrained logistic regression model by LBFGSB.
Since 3.1.0, it supports stacking instances into blocks and using GEMV/GEMM for better performance. The block size will be 1.0 MB, if param maxBlockSizeInMB is set 0.0 by default.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.spark.internal.Logging
org.apache.spark.internal.Logging.LogStringContext, org.apache.spark.internal.Logging.SparkShellLoggingFilter -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal IntParamParam for suggested depth for treeAggregate (>= 2).Creates a copy of this instance with the same UID and some extra params.final DoubleParamParam for the ElasticNet mixing parameter, in range [0, 1].family()final BooleanParamParam for whether to fit an intercept term.doubledouble[]static LogisticRegressionfinal DoubleParamParam for Maximum memory in MB for stacking input data into blocks.final IntParammaxIter()Param for maximum number of iterations (>= 0).static MLReader<T>read()final DoubleParamregParam()Param for regularization parameter (>= 0).setAggregationDepth(int value) Suggested depth for treeAggregate (greater than or equal to 2).setElasticNetParam(double value) Set the ElasticNet mixing parameter.Sets the value of paramfamily().setFitIntercept(boolean value) Whether to fit an intercept term.Set the lower bounds on coefficients if fitting under bound constrained optimization.setLowerBoundsOnIntercepts(Vector value) Set the lower bounds on intercepts if fitting under bound constrained optimization.setMaxBlockSizeInMB(double value) Sets the value of parammaxBlockSizeInMB().setMaxIter(int value) Set the maximum number of iterations.setRegParam(double value) Set the regularization parameter.setStandardization(boolean value) Whether to standardize the training features before fitting the model.setThreshold(double value) setThresholds(double[] value) setTol(double value) Set the convergence tolerance of iterations.Set the upper bounds on coefficients if fitting under bound constrained optimization.setUpperBoundsOnIntercepts(Vector value) Set the upper bounds on intercepts if fitting under bound constrained optimization.setWeightCol(String value) Sets the value of paramweightCol().final BooleanParamParam for whether to standardize the training features before fitting the model.Param for threshold in binary classification prediction, in range [0, 1].final DoubleParamtol()Param for the convergence tolerance for iterative algorithms (>= 0).uid()An immutable unique ID for the object and its derivatives.Param for weight column name.Methods inherited from class org.apache.spark.ml.classification.ProbabilisticClassifier
probabilityCol, setProbabilityCol, thresholdsMethods inherited from class org.apache.spark.ml.classification.Classifier
rawPredictionCol, setRawPredictionColMethods inherited from class org.apache.spark.ml.Predictor
featuresCol, fit, labelCol, predictionCol, setFeaturesCol, setLabelCol, setPredictionCol, transformSchemaMethods inherited from class org.apache.spark.ml.PipelineStage
paramsMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.spark.ml.util.DefaultParamsWritable
writeMethods inherited from interface org.apache.spark.ml.param.shared.HasAggregationDepth
getAggregationDepthMethods inherited from interface org.apache.spark.ml.param.shared.HasElasticNetParam
getElasticNetParamMethods inherited from interface org.apache.spark.ml.param.shared.HasFeaturesCol
featuresCol, getFeaturesColMethods inherited from interface org.apache.spark.ml.param.shared.HasFitIntercept
getFitInterceptMethods inherited from interface org.apache.spark.ml.param.shared.HasLabelCol
getLabelCol, labelColMethods inherited from interface org.apache.spark.ml.param.shared.HasMaxBlockSizeInMB
getMaxBlockSizeInMBMethods inherited from interface org.apache.spark.ml.param.shared.HasMaxIter
getMaxIterMethods inherited from interface org.apache.spark.ml.param.shared.HasPredictionCol
getPredictionCol, predictionColMethods inherited from interface org.apache.spark.ml.param.shared.HasProbabilityCol
getProbabilityCol, probabilityColMethods inherited from interface org.apache.spark.ml.param.shared.HasRawPredictionCol
getRawPredictionCol, rawPredictionColMethods inherited from interface org.apache.spark.ml.param.shared.HasRegParam
getRegParamMethods inherited from interface org.apache.spark.ml.param.shared.HasStandardization
getStandardizationMethods inherited from interface org.apache.spark.ml.param.shared.HasThresholds
thresholdsMethods inherited from interface org.apache.spark.ml.param.shared.HasWeightCol
getWeightColMethods inherited from interface org.apache.spark.ml.util.Identifiable
toStringMethods inherited from interface org.apache.spark.internal.Logging
initializeForcefully, initializeLogIfNecessary, initializeLogIfNecessary, initializeLogIfNecessary$default$2, isTraceEnabled, log, logBasedOnLevel, logDebug, logDebug, logDebug, logDebug, logError, logError, logError, logError, logInfo, logInfo, logInfo, logInfo, logName, LogStringContext, logTrace, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, logWarning, MDC, org$apache$spark$internal$Logging$$log_, org$apache$spark$internal$Logging$$log__$eq, withLogContextMethods inherited from interface org.apache.spark.ml.classification.LogisticRegressionParams
checkThresholdConsistency, getFamily, getLowerBoundsOnCoefficients, getLowerBoundsOnIntercepts, getUpperBoundsOnCoefficients, getUpperBoundsOnIntercepts, org$apache$spark$ml$classification$LogisticRegressionParams$_setter_$family_$eq, org$apache$spark$ml$classification$LogisticRegressionParams$_setter_$lowerBoundsOnCoefficients_$eq, org$apache$spark$ml$classification$LogisticRegressionParams$_setter_$lowerBoundsOnIntercepts_$eq, org$apache$spark$ml$classification$LogisticRegressionParams$_setter_$upperBoundsOnCoefficients_$eq, org$apache$spark$ml$classification$LogisticRegressionParams$_setter_$upperBoundsOnIntercepts_$eq, usingBoundConstrainedOptimization, validateAndTransformSchemaMethods inherited from interface org.apache.spark.ml.util.MLWritable
saveMethods inherited from interface org.apache.spark.ml.param.Params
clear, copyValues, defaultCopy, defaultParamMap, estimateMatadataSize, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, onParamChange, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
-
Constructor Details
-
LogisticRegression
-
LogisticRegression
public LogisticRegression()
-
-
Method Details
-
load
-
read
-
family
- Specified by:
familyin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
lowerBoundsOnCoefficients
- Specified by:
lowerBoundsOnCoefficientsin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
upperBoundsOnCoefficients
- Specified by:
upperBoundsOnCoefficientsin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
lowerBoundsOnIntercepts
- Specified by:
lowerBoundsOnInterceptsin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
upperBoundsOnIntercepts
- Specified by:
upperBoundsOnInterceptsin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
maxBlockSizeInMB
Description copied from interface:HasMaxBlockSizeInMBParam for Maximum memory in MB for stacking input data into blocks. Data is stacked within partitions. If more than remaining data size in a partition then it is adjusted to the data size. Default 0.0 represents choosing optimal value, depends on specific algorithm. Must be >= 0..- Specified by:
maxBlockSizeInMBin interfaceHasMaxBlockSizeInMB- Returns:
- (undocumented)
-
aggregationDepth
Description copied from interface:HasAggregationDepthParam for suggested depth for treeAggregate (>= 2).- Specified by:
aggregationDepthin interfaceHasAggregationDepth- Returns:
- (undocumented)
-
threshold
Description copied from interface:HasThresholdParam for threshold in binary classification prediction, in range [0, 1].- Specified by:
thresholdin interfaceHasThreshold- Returns:
- (undocumented)
-
weightCol
Description copied from interface:HasWeightColParam for weight column name. If this is not set or empty, we treat all instance weights as 1.0.- Specified by:
weightColin interfaceHasWeightCol- Returns:
- (undocumented)
-
standardization
Description copied from interface:HasStandardizationParam for whether to standardize the training features before fitting the model.- Specified by:
standardizationin interfaceHasStandardization- Returns:
- (undocumented)
-
tol
Description copied from interface:HasTolParam for the convergence tolerance for iterative algorithms (>= 0). -
fitIntercept
Description copied from interface:HasFitInterceptParam for whether to fit an intercept term.- Specified by:
fitInterceptin interfaceHasFitIntercept- Returns:
- (undocumented)
-
maxIter
Description copied from interface:HasMaxIterParam for maximum number of iterations (>= 0).- Specified by:
maxIterin interfaceHasMaxIter- Returns:
- (undocumented)
-
elasticNetParam
Description copied from interface:HasElasticNetParamParam for the ElasticNet mixing parameter, in range [0, 1]. For alpha = 0, the penalty is an L2 penalty. For alpha = 1, it is an L1 penalty.- Specified by:
elasticNetParamin interfaceHasElasticNetParam- Returns:
- (undocumented)
-
regParam
Description copied from interface:HasRegParamParam for regularization parameter (>= 0).- Specified by:
regParamin interfaceHasRegParam- Returns:
- (undocumented)
-
uid
Description copied from interface:IdentifiableAn immutable unique ID for the object and its derivatives.- Specified by:
uidin interfaceIdentifiable- Returns:
- (undocumented)
-
setRegParam
Set the regularization parameter. Default is 0.0.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setElasticNetParam
Set the ElasticNet mixing parameter. For alpha = 0, the penalty is an L2 penalty. For alpha = 1, it is an L1 penalty. For alpha in (0,1), the penalty is a combination of L1 and L2. Default is 0.0 which is an L2 penalty.Note: Fitting under bound constrained optimization only supports L2 regularization, so throws exception if this param is non-zero value.
- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setMaxIter
Set the maximum number of iterations. Default is 100.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setTol
Set the convergence tolerance of iterations. Smaller value will lead to higher accuracy at the cost of more iterations. Default is 1E-6.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setFitIntercept
Whether to fit an intercept term. Default is true.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setFamily
Sets the value of paramfamily(). Default is "auto".- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setStandardization
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. In R's GLMNET package, the default behavior is true as well. Default is true.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setThreshold
- Specified by:
setThresholdin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
getThreshold
public double getThreshold()- Specified by:
getThresholdin interfaceHasThreshold- Specified by:
getThresholdin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
setWeightCol
Sets the value of paramweightCol(). If this is not set or empty, we treat all instance weights as 1.0. Default is not set, so all instances have weight one.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setThresholds
- Specified by:
setThresholdsin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams- Overrides:
setThresholdsin classProbabilisticClassifier<Vector,LogisticRegression, LogisticRegressionModel>
-
getThresholds
public double[] getThresholds()- Specified by:
getThresholdsin interfaceHasThresholds- Specified by:
getThresholdsin interfaceorg.apache.spark.ml.classification.LogisticRegressionParams
-
setAggregationDepth
Suggested 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. Default is 2.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setLowerBoundsOnCoefficients
Set the lower bounds on coefficients if fitting under bound constrained optimization.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setUpperBoundsOnCoefficients
Set the upper bounds on coefficients if fitting under bound constrained optimization.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setLowerBoundsOnIntercepts
Set the lower bounds on intercepts if fitting under bound constrained optimization.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setUpperBoundsOnIntercepts
Set the upper bounds on intercepts if fitting under bound constrained optimization.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setMaxBlockSizeInMB
Sets the value of parammaxBlockSizeInMB(). Default is 0.0, then 1.0 MB will be chosen.- Parameters:
value- (undocumented)- Returns:
- (undocumented)
-
setInitialModel
-
copy
Description copied from interface:ParamsCreates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. SeedefaultCopy().- Specified by:
copyin interfaceParams- Specified by:
copyin classPredictor<Vector,LogisticRegression, LogisticRegressionModel> - Parameters:
extra- (undocumented)- Returns:
- (undocumented)
-