public class LogisticRegression extends ProbabilisticClassifier<Vector,LogisticRegression,LogisticRegressionModel>
Constructor and Description |
---|
LogisticRegression() |
LogisticRegression(java.lang.String uid) |
Modifier and Type | Method and Description |
---|---|
protected static <T> T |
$(Param<T> param) |
protected static void |
checkThresholdConsistency() |
void |
checkThresholdConsistency()
If
threshold and thresholds are both set, ensures they are consistent. |
static Params |
clear(Param<?> param) |
LogisticRegression |
copy(ParamMap extra)
Creates a copy of this instance with the same UID and some extra params.
|
protected static <T extends Params> |
copyValues(T to,
ParamMap extra) |
protected static <T extends Params> |
copyValues$default$2() |
protected static <T extends Params> |
defaultCopy(ParamMap extra) |
static DoubleParam |
elasticNetParam() |
static java.lang.String |
explainParam(Param<?> param) |
static java.lang.String |
explainParams() |
protected static RDD<LabeledPoint> |
extractLabeledPoints(Dataset<?> dataset) |
protected static RDD<LabeledPoint> |
extractLabeledPoints(Dataset<?> dataset,
int numClasses) |
static ParamMap |
extractParamMap() |
static ParamMap |
extractParamMap(ParamMap extra) |
static Param<java.lang.String> |
featuresCol() |
Param<java.lang.String> |
featuresCol()
Param for features column name.
|
static M |
fit(Dataset<?> dataset) |
static M |
fit(Dataset<?> dataset,
ParamMap paramMap) |
static scala.collection.Seq<M> |
fit(Dataset<?> dataset,
ParamMap[] paramMaps) |
static M |
fit(Dataset<?> dataset,
ParamPair<?> firstParamPair,
ParamPair<?>... otherParamPairs) |
static M |
fit(Dataset<?> dataset,
ParamPair<?> firstParamPair,
scala.collection.Seq<ParamPair<?>> otherParamPairs) |
static BooleanParam |
fitIntercept() |
static <T> scala.Option<T> |
get(Param<T> param) |
static <T> scala.Option<T> |
getDefault(Param<T> param) |
static double |
getElasticNetParam() |
static java.lang.String |
getFeaturesCol() |
java.lang.String |
getFeaturesCol() |
static boolean |
getFitIntercept() |
static java.lang.String |
getLabelCol() |
java.lang.String |
getLabelCol() |
static int |
getMaxIter() |
protected static int |
getNumClasses(Dataset<?> dataset,
int maxNumClasses) |
protected static int |
getNumClasses$default$2() |
static <T> T |
getOrDefault(Param<T> param) |
static Param<java.lang.Object> |
getParam(java.lang.String paramName) |
static java.lang.String |
getPredictionCol() |
java.lang.String |
getPredictionCol() |
static java.lang.String |
getProbabilityCol() |
static java.lang.String |
getRawPredictionCol() |
java.lang.String |
getRawPredictionCol() |
static double |
getRegParam() |
static boolean |
getStandardization() |
double |
getThreshold()
Get threshold for binary classification.
|
double[] |
getThresholds()
Get thresholds for binary or multiclass classification.
|
static double |
getTol() |
static java.lang.String |
getWeightCol() |
static <T> boolean |
hasDefault(Param<T> param) |
static boolean |
hasParam(java.lang.String paramName) |
protected static void |
initializeLogIfNecessary(boolean isInterpreter) |
static boolean |
isDefined(Param<?> param) |
static boolean |
isSet(Param<?> param) |
protected static boolean |
isTraceEnabled() |
static Param<java.lang.String> |
labelCol() |
Param<java.lang.String> |
labelCol()
Param for label column name.
|
static LogisticRegression |
load(java.lang.String path) |
protected static org.slf4j.Logger |
log() |
protected static void |
logDebug(scala.Function0<java.lang.String> msg) |
protected static void |
logDebug(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logError(scala.Function0<java.lang.String> msg) |
protected static void |
logError(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logInfo(scala.Function0<java.lang.String> msg) |
protected static void |
logInfo(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static java.lang.String |
logName() |
protected static void |
logTrace(scala.Function0<java.lang.String> msg) |
protected static void |
logTrace(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
protected static void |
logWarning(scala.Function0<java.lang.String> msg) |
protected static void |
logWarning(scala.Function0<java.lang.String> msg,
java.lang.Throwable throwable) |
static IntParam |
maxIter() |
static Param<?>[] |
params() |
static Param<java.lang.String> |
predictionCol() |
Param<java.lang.String> |
predictionCol()
Param for prediction column name.
|
static Param<java.lang.String> |
probabilityCol() |
static Param<java.lang.String> |
rawPredictionCol() |
Param<java.lang.String> |
rawPredictionCol()
Param for raw prediction (a.k.a.
|
static DoubleParam |
regParam() |
static void |
save(java.lang.String path) |
static <T> Params |
set(Param<T> param,
T value) |
protected static Params |
set(ParamPair<?> paramPair) |
protected static Params |
set(java.lang.String param,
java.lang.Object value) |
protected static <T> Params |
setDefault(Param<T> param,
T value) |
protected static Params |
setDefault(scala.collection.Seq<ParamPair<?>> paramPairs) |
LogisticRegression |
setElasticNetParam(double value)
Set the ElasticNet mixing parameter.
|
static Learner |
setFeaturesCol(java.lang.String value) |
LogisticRegression |
setFitIntercept(boolean value)
Whether to fit an intercept term.
|
static Learner |
setLabelCol(java.lang.String value) |
LogisticRegression |
setMaxIter(int value)
Set the maximum number of iterations.
|
static Learner |
setPredictionCol(java.lang.String value) |
static E |
setProbabilityCol(java.lang.String value) |
static E |
setRawPredictionCol(java.lang.String value) |
LogisticRegression |
setRegParam(double value)
Set the regularization parameter.
|
LogisticRegression |
setStandardization(boolean value)
Whether to standardize the training features before fitting the model.
|
LogisticRegression |
setThreshold(double value)
Set threshold in binary classification, in range [0, 1].
|
LogisticRegression |
setThresholds(double[] value)
Set thresholds in multiclass (or binary) classification to adjust the probability of
predicting each class.
|
LogisticRegression |
setTol(double value)
Set the convergence tolerance of iterations.
|
LogisticRegression |
setWeightCol(java.lang.String value)
Whether to over-/under-sample training instances according to the given weights in weightCol.
|
static BooleanParam |
standardization() |
static DoubleParam |
threshold() |
static DoubleArrayParam |
thresholds() |
static DoubleParam |
tol() |
static java.lang.String |
toString() |
protected LogisticRegressionModel |
train(Dataset<?> dataset)
Train a model using the given dataset and parameters.
|
protected LogisticRegressionModel |
train(Dataset<?> dataset,
boolean handlePersistence) |
static StructType |
transformSchema(StructType schema) |
protected static StructType |
transformSchema(StructType schema,
boolean logging) |
java.lang.String |
uid()
An immutable unique ID for the object and its derivatives.
|
protected static StructType |
validateAndTransformSchema(StructType schema,
boolean fitting,
DataType featuresDataType) |
StructType |
validateAndTransformSchema(StructType schema,
boolean fitting,
DataType featuresDataType) |
StructType |
validateAndTransformSchema(StructType schema,
boolean fitting,
DataType featuresDataType)
Validates and transforms the input schema with the provided param map.
|
static void |
validateParams() |
void |
validateParams()
Validates parameter values stored internally.
|
static Param<java.lang.String> |
weightCol() |
static MLWriter |
write() |
setProbabilityCol
extractLabeledPoints, getNumClasses, setRawPredictionCol
extractLabeledPoints, fit, setFeaturesCol, setLabelCol, setPredictionCol, transformSchema
transformSchema
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
clear, copyValues, defaultCopy, defaultParamMap, explainParam, explainParams, extractParamMap, extractParamMap, get, getDefault, getOrDefault, getParam, hasDefault, hasParam, isDefined, isSet, paramMap, params, set, set, set, setDefault, setDefault, shouldOwn
toString
public LogisticRegression(java.lang.String uid)
public LogisticRegression()
public static LogisticRegression load(java.lang.String path)
public static java.lang.String toString()
public static Param<?>[] params()
public static java.lang.String explainParam(Param<?> param)
public static java.lang.String explainParams()
public static final boolean isSet(Param<?> param)
public static final boolean isDefined(Param<?> param)
public static boolean hasParam(java.lang.String paramName)
public static Param<java.lang.Object> getParam(java.lang.String paramName)
protected static final Params set(java.lang.String param, java.lang.Object value)
public static final <T> scala.Option<T> get(Param<T> param)
public static final <T> T getOrDefault(Param<T> param)
protected static final <T> T $(Param<T> param)
public static final <T> scala.Option<T> getDefault(Param<T> param)
public static final <T> boolean hasDefault(Param<T> param)
public static final ParamMap extractParamMap()
protected static java.lang.String logName()
protected static org.slf4j.Logger log()
protected static void logInfo(scala.Function0<java.lang.String> msg)
protected static void logDebug(scala.Function0<java.lang.String> msg)
protected static void logTrace(scala.Function0<java.lang.String> msg)
protected static void logWarning(scala.Function0<java.lang.String> msg)
protected static void logError(scala.Function0<java.lang.String> msg)
protected static void logInfo(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logDebug(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logTrace(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logWarning(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static void logError(scala.Function0<java.lang.String> msg, java.lang.Throwable throwable)
protected static boolean isTraceEnabled()
protected static void initializeLogIfNecessary(boolean isInterpreter)
protected static StructType transformSchema(StructType schema, boolean logging)
public static M fit(Dataset<?> dataset, ParamPair<?> firstParamPair, scala.collection.Seq<ParamPair<?>> otherParamPairs)
public static M fit(Dataset<?> dataset, ParamPair<?> firstParamPair, ParamPair<?>... otherParamPairs)
public static final Param<java.lang.String> labelCol()
public static final java.lang.String getLabelCol()
public static final Param<java.lang.String> featuresCol()
public static final java.lang.String getFeaturesCol()
public static final Param<java.lang.String> predictionCol()
public static final java.lang.String getPredictionCol()
public static Learner setLabelCol(java.lang.String value)
public static Learner setFeaturesCol(java.lang.String value)
public static Learner setPredictionCol(java.lang.String value)
public static M fit(Dataset<?> dataset)
public static StructType transformSchema(StructType schema)
protected static RDD<LabeledPoint> extractLabeledPoints(Dataset<?> dataset)
public static final Param<java.lang.String> rawPredictionCol()
public static final java.lang.String getRawPredictionCol()
public static E setRawPredictionCol(java.lang.String value)
protected static RDD<LabeledPoint> extractLabeledPoints(Dataset<?> dataset, int numClasses)
protected static int getNumClasses(Dataset<?> dataset, int maxNumClasses)
protected static int getNumClasses$default$2()
public static final Param<java.lang.String> probabilityCol()
public static final java.lang.String getProbabilityCol()
public static final DoubleArrayParam thresholds()
protected static StructType validateAndTransformSchema(StructType schema, boolean fitting, DataType featuresDataType)
public static E setProbabilityCol(java.lang.String value)
public static final DoubleParam regParam()
public static final double getRegParam()
public static final DoubleParam elasticNetParam()
public static final double getElasticNetParam()
public static final IntParam maxIter()
public static final int getMaxIter()
public static final BooleanParam fitIntercept()
public static final boolean getFitIntercept()
public static final DoubleParam tol()
public static final double getTol()
public static final BooleanParam standardization()
public static final boolean getStandardization()
public static final Param<java.lang.String> weightCol()
public static final java.lang.String getWeightCol()
public static final DoubleParam threshold()
protected static void checkThresholdConsistency()
public static void validateParams()
public static void save(java.lang.String path) throws java.io.IOException
java.io.IOException
public static MLWriter write()
public java.lang.String uid()
Identifiable
uid
in interface Identifiable
public LogisticRegression setRegParam(double value)
value
- (undocumented)public LogisticRegression setElasticNetParam(double value)
value
- (undocumented)public LogisticRegression setMaxIter(int value)
value
- (undocumented)public LogisticRegression setTol(double value)
value
- (undocumented)public LogisticRegression setFitIntercept(boolean value)
value
- (undocumented)public LogisticRegression setStandardization(boolean value)
value
- (undocumented)public LogisticRegression setThreshold(double value)
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: Calling this with threshold p is equivalent to calling setThresholds(Array(1-p, p))
.
When setThreshold()
is called, any user-set value for thresholds
will be cleared.
If both threshold
and thresholds
are set in a ParamMap, then they must be
equivalent.
Default is 0.5.
value
- (undocumented)public double getThreshold()
If threshold
is set, returns that value.
Otherwise, if thresholds
is set with length 2 (i.e., binary classification),
this returns the equivalent threshold:
1 / (1 + thresholds(0) / thresholds(1))
.
Otherwise, returns {@link threshold} default value.
@group getParam
@throws IllegalArgumentException if {@link thresholds} is set to an array of length other than 2.public LogisticRegression setWeightCol(java.lang.String value)
value
- (undocumented)public LogisticRegression setThresholds(double[] value)
Note: When setThresholds()
is called, any user-set value for threshold
will be cleared.
If both threshold
and thresholds
are set in a ParamMap, then they must be
equivalent.
setThresholds
in class ProbabilisticClassifier<Vector,LogisticRegression,LogisticRegressionModel>
value
- (undocumented)public double[] getThresholds()
If thresholds
is set, return its value.
Otherwise, if threshold
is set, return the equivalent thresholds for binary
classification: (1-threshold, threshold).
If neither are set, throw an exception.
protected LogisticRegressionModel train(Dataset<?> dataset)
Predictor
fit()
to avoid dealing with schema validation
and copying parameters into the model.
train
in class Predictor<Vector,LogisticRegression,LogisticRegressionModel>
dataset
- Training datasetprotected LogisticRegressionModel train(Dataset<?> dataset, boolean handlePersistence)
public LogisticRegression copy(ParamMap extra)
Params
copy
in interface Params
copy
in class Predictor<Vector,LogisticRegression,LogisticRegressionModel>
extra
- (undocumented)defaultCopy()
public void checkThresholdConsistency()
threshold
and thresholds
are both set, ensures they are consistent.java.lang.IllegalArgumentException
- if threshold
and thresholds
are not equivalentpublic void validateParams()
Params
This only needs to check for interactions between parameters.
Parameter value checks which do not depend on other parameters are handled by
Param.validate()
. This method does not handle input/output column parameters;
those are checked during schema validation.
public StructType validateAndTransformSchema(StructType schema, boolean fitting, DataType featuresDataType)
public Param<java.lang.String> rawPredictionCol()
public java.lang.String getRawPredictionCol()
public StructType validateAndTransformSchema(StructType schema, boolean fitting, DataType featuresDataType)
schema
- input schemafitting
- whether this is in fittingfeaturesDataType
- SQL DataType for FeaturesType.
E.g., VectorUDT
for vector features.public Param<java.lang.String> labelCol()
public java.lang.String getLabelCol()
public Param<java.lang.String> featuresCol()
public java.lang.String getFeaturesCol()
public Param<java.lang.String> predictionCol()
public java.lang.String getPredictionCol()