public class LogisticRegressionModel extends ProbabilisticClassificationModel<Vector,LogisticRegressionModel> implements MLWritable
LogisticRegression
.Modifier and Type | Method and Description |
---|---|
static IntParam |
aggregationDepth() |
BinaryLogisticRegressionTrainingSummary |
binarySummary()
Gets summary of model on training set.
|
void |
checkThresholdConsistency()
If
threshold and thresholds are both set, ensures they are consistent. |
static Params |
clear(Param<?> param) |
Matrix |
coefficientMatrix() |
Vector |
coefficients()
A vector of model coefficients for "binomial" logistic regression.
|
LogisticRegressionModel |
copy(ParamMap extra)
Creates a copy of this instance with the same UID and some extra params.
|
static DoubleParam |
elasticNetParam() |
LogisticRegressionSummary |
evaluate(Dataset<?> dataset)
Evaluates the model on a test dataset.
|
static String |
explainParam(Param<?> param) |
static String |
explainParams() |
static ParamMap |
extractParamMap() |
static ParamMap |
extractParamMap(ParamMap extra) |
static Param<String> |
family() |
Param<String> |
family()
Param for the name of family which is a description of the label distribution
to be used in the model.
|
static Param<String> |
featuresCol() |
static BooleanParam |
fitIntercept() |
static <T> scala.Option<T> |
get(Param<T> param) |
static int |
getAggregationDepth() |
static <T> scala.Option<T> |
getDefault(Param<T> param) |
static double |
getElasticNetParam() |
static String |
getFamily() |
String |
getFamily() |
static String |
getFeaturesCol() |
static boolean |
getFitIntercept() |
static String |
getLabelCol() |
static Matrix |
getLowerBoundsOnCoefficients() |
Matrix |
getLowerBoundsOnCoefficients() |
static Vector |
getLowerBoundsOnIntercepts() |
Vector |
getLowerBoundsOnIntercepts() |
static int |
getMaxIter() |
static <T> T |
getOrDefault(Param<T> param) |
static Param<Object> |
getParam(String paramName) |
static String |
getPredictionCol() |
static String |
getProbabilityCol() |
static 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 Matrix |
getUpperBoundsOnCoefficients() |
Matrix |
getUpperBoundsOnCoefficients() |
static Vector |
getUpperBoundsOnIntercepts() |
Vector |
getUpperBoundsOnIntercepts() |
static String |
getWeightCol() |
static <T> boolean |
hasDefault(Param<T> param) |
static boolean |
hasParam(String paramName) |
static boolean |
hasParent() |
boolean |
hasSummary()
Indicates whether a training summary exists for this model instance.
|
double |
intercept()
The model intercept for "binomial" logistic regression.
|
Vector |
interceptVector() |
static boolean |
isDefined(Param<?> param) |
static boolean |
isSet(Param<?> param) |
static Param<String> |
labelCol() |
static LogisticRegressionModel |
load(String path) |
static Param<Matrix> |
lowerBoundsOnCoefficients() |
Param<Matrix> |
lowerBoundsOnCoefficients()
The lower bounds on coefficients if fitting under bound constrained optimization.
|
static Param<Vector> |
lowerBoundsOnIntercepts() |
Param<Vector> |
lowerBoundsOnIntercepts()
The lower bounds on intercepts if fitting under bound constrained optimization.
|
static IntParam |
maxIter() |
int |
numClasses() |
int |
numFeatures() |
static Param<?>[] |
params() |
static void |
parent_$eq(Estimator<M> x$1) |
static Estimator<M> |
parent() |
static Param<String> |
predictionCol() |
static Param<String> |
probabilityCol() |
static Param<String> |
rawPredictionCol() |
static MLReader<LogisticRegressionModel> |
read() |
static DoubleParam |
regParam() |
static void |
save(String path) |
static <T> Params |
set(Param<T> param,
T value) |
static M |
setFeaturesCol(String value) |
static M |
setParent(Estimator<M> parent) |
static M |
setPredictionCol(String value) |
static M |
setProbabilityCol(String value) |
static M |
setRawPredictionCol(String value) |
LogisticRegressionModel |
setThreshold(double value)
Set threshold in binary classification, in range [0, 1].
|
LogisticRegressionModel |
setThresholds(double[] value)
Set thresholds in multiclass (or binary) classification to adjust the probability of
predicting each class.
|
static BooleanParam |
standardization() |
LogisticRegressionTrainingSummary |
summary()
Gets summary of model on training set.
|
static DoubleParam |
threshold() |
static DoubleArrayParam |
thresholds() |
static DoubleParam |
tol() |
static String |
toString() |
static Dataset<Row> |
transform(Dataset<?> dataset) |
static Dataset<Row> |
transform(Dataset<?> dataset,
ParamMap paramMap) |
static Dataset<Row> |
transform(Dataset<?> dataset,
ParamPair<?> firstParamPair,
ParamPair<?>... otherParamPairs) |
static Dataset<Row> |
transform(Dataset<?> dataset,
ParamPair<?> firstParamPair,
scala.collection.Seq<ParamPair<?>> otherParamPairs) |
static StructType |
transformSchema(StructType schema) |
String |
uid()
An immutable unique ID for the object and its derivatives.
|
static Param<Matrix> |
upperBoundsOnCoefficients() |
Param<Matrix> |
upperBoundsOnCoefficients()
The upper bounds on coefficients if fitting under bound constrained optimization.
|
static Param<Vector> |
upperBoundsOnIntercepts() |
Param<Vector> |
upperBoundsOnIntercepts()
The upper bounds on intercepts if fitting under bound constrained optimization.
|
boolean |
usingBoundConstrainedOptimization() |
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 Param<String> |
weightCol() |
MLWriter |
write()
Returns a
MLWriter instance for this ML instance. |
normalizeToProbabilitiesInPlace, setProbabilityCol, transform
setRawPredictionCol
setFeaturesCol, setPredictionCol, transformSchema
transform, transform, transform
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRawPredictionCol, rawPredictionCol
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
getProbabilityCol, probabilityCol
thresholds
getRegParam, regParam
elasticNetParam, getElasticNetParam
getMaxIter, maxIter
fitIntercept, getFitIntercept
getStandardization, standardization
getWeightCol, weightCol
threshold
aggregationDepth, getAggregationDepth
save
getLabelCol, labelCol
featuresCol, getFeaturesCol
getPredictionCol, predictionCol
initializeLogging, initializeLogIfNecessary, initializeLogIfNecessary, isTraceEnabled, log_, log, logDebug, logDebug, logError, logError, logInfo, logInfo, logName, logTrace, logTrace, logWarning, logWarning
public static MLReader<LogisticRegressionModel> read()
public static LogisticRegressionModel load(String path)
public static String toString()
public static Param<?>[] params()
public static String explainParam(Param<?> param)
public static String explainParams()
public static final boolean isSet(Param<?> param)
public static final boolean isDefined(Param<?> param)
public static boolean hasParam(String paramName)
public static Param<Object> getParam(String paramName)
public static final <T> scala.Option<T> get(Param<T> param)
public static final <T> T getOrDefault(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()
public static Dataset<Row> transform(Dataset<?> dataset, ParamPair<?> firstParamPair, scala.collection.Seq<ParamPair<?>> otherParamPairs)
public static Dataset<Row> transform(Dataset<?> dataset, ParamPair<?> firstParamPair, ParamPair<?>... otherParamPairs)
public static Estimator<M> parent()
public static void parent_$eq(Estimator<M> x$1)
public static M setParent(Estimator<M> parent)
public static boolean hasParent()
public static final Param<String> labelCol()
public static final String getLabelCol()
public static final Param<String> featuresCol()
public static final String getFeaturesCol()
public static final Param<String> predictionCol()
public static final String getPredictionCol()
public static M setFeaturesCol(String value)
public static M setPredictionCol(String value)
public static StructType transformSchema(StructType schema)
public static final Param<String> rawPredictionCol()
public static final String getRawPredictionCol()
public static M setRawPredictionCol(String value)
public static final Param<String> probabilityCol()
public static final String getProbabilityCol()
public static final DoubleArrayParam thresholds()
public static M setProbabilityCol(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<String> weightCol()
public static final String getWeightCol()
public static DoubleParam threshold()
public static final IntParam aggregationDepth()
public static final int getAggregationDepth()
public static final Param<String> family()
public static String getFamily()
public static Matrix getLowerBoundsOnCoefficients()
public static Matrix getUpperBoundsOnCoefficients()
public static Vector getLowerBoundsOnIntercepts()
public static Vector getUpperBoundsOnIntercepts()
public static void save(String path) throws java.io.IOException
java.io.IOException
public String uid()
Identifiable
uid
in interface Identifiable
uid
in class ProbabilisticClassificationModel<Vector,LogisticRegressionModel>
public Matrix coefficientMatrix()
public Vector interceptVector()
public int numClasses()
numClasses
in class ProbabilisticClassificationModel<Vector,LogisticRegressionModel>
public Vector coefficients()
public double intercept()
public LogisticRegressionModel setThreshold(double value)
If the estimated probability of class label 1 is greater than 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 thresholds
is set with length 2 (i.e., binary classification),
this returns the equivalent threshold:
1 / (1 + thresholds(0) / thresholds(1))
.
Otherwise, returns `threshold` if set, or its default value if unset.
@group getParam
@throws IllegalArgumentException if `thresholds` is set to an array of length other than 2.public LogisticRegressionModel 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 ProbabilisticClassificationModel<Vector,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.
getThresholds
in class ProbabilisticClassificationModel<Vector,LogisticRegressionModel>
public int numFeatures()
numFeatures
in class ProbabilisticClassificationModel<Vector,LogisticRegressionModel>
public LogisticRegressionTrainingSummary summary()
trainingSummary == None
.public BinaryLogisticRegressionTrainingSummary binarySummary()
trainingSummary == None
or it is a multiclass model.public boolean hasSummary()
public LogisticRegressionSummary evaluate(Dataset<?> dataset)
dataset
- Test dataset to evaluate model on.public LogisticRegressionModel copy(ParamMap extra)
Params
defaultCopy()
.copy
in interface Params
copy
in class ProbabilisticClassificationModel<Vector,LogisticRegressionModel>
extra
- (undocumented)public MLWriter write()
MLWriter
instance for this ML instance.
For LogisticRegressionModel
, this does NOT currently save the training summary
.
An option to save summary
may be added in the future.
This also does not save the parent
currently.
write
in interface MLWritable
public Param<String> family()
public String getFamily()
public void checkThresholdConsistency()
threshold
and thresholds
are both set, ensures they are consistent.
IllegalArgumentException
- if threshold
and thresholds
are not equivalentpublic Param<Matrix> lowerBoundsOnCoefficients()
public Matrix getLowerBoundsOnCoefficients()
public Param<Matrix> upperBoundsOnCoefficients()
public Matrix getUpperBoundsOnCoefficients()
public Param<Vector> lowerBoundsOnIntercepts()
public Vector getLowerBoundsOnIntercepts()
public Param<Vector> upperBoundsOnIntercepts()
public Vector getUpperBoundsOnIntercepts()
public boolean usingBoundConstrainedOptimization()
public StructType validateAndTransformSchema(StructType schema, boolean fitting, DataType featuresDataType)
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.