Skip to content

Commit

Permalink
[SPARK-19155][ML] MLlib GeneralizedLinearRegression family and link s…
Browse files Browse the repository at this point in the history
…hould case insensitive

## What changes were proposed in this pull request?
MLlib ```GeneralizedLinearRegression``` ```family``` and ```link``` should be case insensitive. This is consistent with some other MLlib params such as [```featureSubsetStrategy```](https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/ml/tree/treeParams.scala#L415).

## How was this patch tested?
Update corresponding tests.

Author: Yanbo Liang <[email protected]>

Closes #16516 from yanboliang/spark-19133.
  • Loading branch information
yanboliang committed Jan 22, 2017
1 parent aa014eb commit 3dcad9f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private[regression] trait GeneralizedLinearRegressionBase extends PredictorParam
final val family: Param[String] = new Param(this, "family",
"The name of family which is a description of the error distribution to be used in the " +
s"model. Supported options: ${supportedFamilyNames.mkString(", ")}.",
ParamValidators.inArray[String](supportedFamilyNames.toArray))
(value: String) => supportedFamilyNames.contains(value.toLowerCase))

/** @group getParam */
@Since("2.0.0")
Expand All @@ -74,7 +74,7 @@ private[regression] trait GeneralizedLinearRegressionBase extends PredictorParam
final val link: Param[String] = new Param(this, "link", "The name of link function " +
"which provides the relationship between the linear predictor and the mean of the " +
s"distribution function. Supported options: ${supportedLinkNames.mkString(", ")}",
ParamValidators.inArray[String](supportedLinkNames.toArray))
(value: String) => supportedLinkNames.contains(value.toLowerCase))

/** @group getParam */
@Since("2.0.0")
Expand Down Expand Up @@ -414,7 +414,7 @@ object GeneralizedLinearRegression extends DefaultParamsReadable[GeneralizedLine
* @param name family name: "gaussian", "binomial", "poisson" or "gamma".
*/
def fromName(name: String): Family = {
name match {
name.toLowerCase match {
case Gaussian.name => Gaussian
case Binomial.name => Binomial
case Poisson.name => Poisson
Expand Down Expand Up @@ -626,7 +626,7 @@ object GeneralizedLinearRegression extends DefaultParamsReadable[GeneralizedLine
* "inverse", "probit", "cloglog" or "sqrt".
*/
def fromName(name: String): Link = {
name match {
name.toLowerCase match {
case Identity.name => Identity
case Logit.name => Logit
case Log.name => Log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ class GeneralizedLinearRegressionSuite
for ((link, dataset) <- Seq(("inverse", datasetGammaInverse),
("identity", datasetGammaIdentity), ("log", datasetGammaLog))) {
for (fitIntercept <- Seq(false, true)) {
val trainer = new GeneralizedLinearRegression().setFamily("gamma").setLink(link)
val trainer = new GeneralizedLinearRegression().setFamily("Gamma").setLink(link)
.setFitIntercept(fitIntercept).setLinkPredictionCol("linkPrediction")
val model = trainer.fit(dataset)
val actual = Vectors.dense(model.intercept, model.coefficients(0), model.coefficients(1))
Expand Down Expand Up @@ -990,7 +990,7 @@ class GeneralizedLinearRegressionSuite
-0.6344390 0.3172195 0.2114797 -0.1586097
*/
val trainer = new GeneralizedLinearRegression()
.setFamily("gamma")
.setFamily("Gamma")
.setWeightCol("weight")

val model = trainer.fit(datasetWithWeight)
Expand Down

0 comments on commit 3dcad9f

Please sign in to comment.