Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DB Tsai committed Jun 2, 2015
1 parent 1ec29d4 commit 136e0dd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object LinearRegressionExample {
s"L1 and L2, default: ${defaultParams.elasticNetParam}")
.action((x, c) => c.copy(elasticNetParam = x))
opt[Int]("maxIter")
.text(s"maximal number of iterations, default: ${defaultParams.maxIter}")
.text(s"maximum number of iterations, default: ${defaultParams.maxIter}")
.action((x, c) => c.copy(maxIter = x))
opt[Double]("tol")
.text(s"the convergence tolerance of iterations, Smaller value will lead " +
Expand Down Expand Up @@ -115,9 +115,6 @@ object LinearRegressionExample {
val (training: DataFrame, test: DataFrame) = DecisionTreeExample.loadDatasets(sc, params.input,
params.dataFormat, params.testInput, "regression", params.fracTest)

// Set up Pipeline
val stages = new mutable.ArrayBuffer[PipelineStage]()

val lir = new LinearRegression()
.setFeaturesCol("features")
.setLabelCol("label")
Expand All @@ -126,23 +123,19 @@ object LinearRegressionExample {
.setMaxIter(params.maxIter)
.setTol(params.tol)

stages += lir
val pipeline = new Pipeline().setStages(stages.toArray)

// Fit the Pipeline
// Train the model
val startTime = System.nanoTime()
val pipelineModel = pipeline.fit(training)
val lirModel = lir.fit(training)
val elapsedTime = (System.nanoTime() - startTime) / 1e9
println(s"Training time: $elapsedTime seconds")

val lirModel = pipelineModel.stages.last.asInstanceOf[LinearRegressionModel]
// Print the weights and intercept for linear regression.
println(s"Weights: ${lirModel.weights} Intercept: ${lirModel.intercept}")

println("Training data results:")
DecisionTreeExample.evaluateRegressionModel(pipelineModel, training, "label")
DecisionTreeExample.evaluateRegressionModel(lirModel, training, "label")
println("Test data results:")
DecisionTreeExample.evaluateRegressionModel(pipelineModel, test, "label")
DecisionTreeExample.evaluateRegressionModel(lirModel, test, "label")

sc.stop()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object LogisticRegressionExample {
s"L1 and L2, default: ${defaultParams.elasticNetParam}")
.action((x, c) => c.copy(elasticNetParam = x))
opt[Int]("maxIter")
.text(s"maximal number of iterations, default: ${defaultParams.maxIter}")
.text(s"maximum number of iterations, default: ${defaultParams.maxIter}")
.action((x, c) => c.copy(maxIter = x))
opt[Boolean]("fitIntercept")
.text(s"whether to fit an intercept term, default: ${defaultParams.fitIntercept}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LogisticRegression(override val uid: String)
setDefault(elasticNetParam -> 0.0)

/**
* Set the maximal number of iterations.
* Set the maximum number of iterations.
* Default is 100.
* @group setParam
*/
Expand All @@ -90,7 +90,11 @@ class LogisticRegression(override val uid: String)
def setTol(value: Double): this.type = set(tol, value)
setDefault(tol -> 1E-6)

/** @group setParam */
/**
* Whether to fit an intercept term.
* Default is true.
* @group setParam
* */
def setFitIntercept(value: Boolean): this.type = set(fitIntercept, value)
setDefault(fitIntercept -> true)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private[shared] object SharedParamsCodeGen {
val params = Seq(
ParamDesc[Double]("regParam", "regularization parameter (>= 0)",
isValid = "ParamValidators.gtEq(0)"),
ParamDesc[Int]("maxIter", "max number of iterations (>= 0)",
ParamDesc[Int]("maxIter", "maximum number of iterations (>= 0)",
isValid = "ParamValidators.gtEq(0)"),
ParamDesc[String]("featuresCol", "features column name", Some("\"features\"")),
ParamDesc[String]("labelCol", "label column name", Some("\"label\"")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ private[ml] trait HasRegParam extends Params {
private[ml] trait HasMaxIter extends Params {

/**
* Param for max number of iterations (>= 0).
* Param for maximum number of iterations (>= 0).
* @group param
*/
final val maxIter: IntParam = new IntParam(this, "maxIter", "max number of iterations (>= 0)", ParamValidators.gtEq(0))
final val maxIter: IntParam = new IntParam(this, "maxIter", "maximum number of iterations (>= 0)", ParamValidators.gtEq(0))

/** @group getParam */
final def getMaxIter: Int = $(maxIter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LinearRegression(override val uid: String)
setDefault(elasticNetParam -> 0.0)

/**
* Set the maximal number of iterations.
* Set the maximum number of iterations.
* Default is 100.
* @group setParam
*/
Expand Down

0 comments on commit 136e0dd

Please sign in to comment.