Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-6705][MLLIB] Add fit intercept api to ml logisticregression #5301

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import org.apache.spark.storage.StorageLevel
* Params for logistic regression.
*/
private[classification] trait LogisticRegressionParams extends ProbabilisticClassifierParams
with HasRegParam with HasMaxIter with HasThreshold
with HasRegParam with HasMaxIter with HasFitIntercept with HasThreshold


/**
Expand All @@ -46,6 +46,7 @@ class LogisticRegression
with LogisticRegressionParams {

setRegParam(0.1)
setFitIntercept(true)
setMaxIter(100)
setThreshold(0.5)

Expand All @@ -55,6 +56,9 @@ class LogisticRegression
/** @group setParam */
def setMaxIter(value: Int): this.type = set(maxIter, value)

/** @group setParam */
def setFitIntercept(value: Boolean): this.type = set(fitIntercept, value)

/** @group setParam */
def setThreshold(value: Double): this.type = set(threshold, value)

Expand All @@ -71,6 +75,7 @@ class LogisticRegression
lr.optimizer
.setRegParam(paramMap(regParam))
.setNumIterations(paramMap(maxIter))
.addIntercept(paramMap(fitIntercept))
val oldModel = lr.run(oldDataset)
val lrm = new LogisticRegressionModel(this, paramMap, oldModel.weights, oldModel.intercept)

Expand Down
11 changes: 11 additions & 0 deletions mllib/src/main/scala/org/apache/spark/ml/param/sharedParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ private[ml] trait HasProbabilityCol extends Params {
def getProbabilityCol: String = get(probabilityCol)
}

private[ml] trait HasFitIntercept extends Params {
/**
* param for fitting the intercept term
* @group param
*/
val fitIntercept: BooleanParam = new BooleanParam(this, "fitIntercept", "fits the intercept term or not")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"fits the intercept term or not" --> "Indicates whether to fit an intercept term"


/** @group getParam */
def getFitIntercept: Boolean = get(fitIntercept)
}

private[ml] trait HasThreshold extends Params {
/**
* param for threshold in (binary) prediction
Expand Down