Github user actuaryzhang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16344#discussion_r96061873
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/regression/GeneralizedLinearRegression.scala
 ---
    @@ -613,25 +758,67 @@ object GeneralizedLinearRegression extends 
DefaultParamsReadable[GeneralizedLine
       private[regression] object Link {
     
         /**
    -     * Gets the [[Link]] object from its name.
    +     * Gets the [[Link]] object based on link and linkPower.
    +     * 1) if family is "tweedie", retrieve object using linkPower
    +     * 2) otherwise, retrieve object based on link name
          *
    -     * @param name link name: "identity", "logit", "log",
    -     *             "inverse", "probit", "cloglog" or "sqrt".
    +     * @param params the parameter map containing link and link power
          */
    -    def fromName(name: String): Link = {
    -      name match {
    -        case Identity.name => Identity
    -        case Logit.name => Logit
    -        case Log.name => Log
    -        case Inverse.name => Inverse
    -        case Probit.name => Probit
    -        case CLogLog.name => CLogLog
    -        case Sqrt.name => Sqrt
    +    def fromParams(params: GeneralizedLinearRegressionBase): Link = {
    +      if (params.getFamily == "tweedie") {
    +        params.getLinkPower match {
    +          case 0.0 => Log
    +          case 1.0 => Identity
    +          case -1.0 => Inverse
    +          case 0.5 => Sqrt
    +          case others => new PowerLink(others)
    +        }
    --- End diff --
    
    The last version of the code only allows setting `linkPower` for tweedie, 
or `link` for non-tweedie. But now since we only give warnings, I need to add 
the logic for checking the correct specification. In the `FamilyAndLink` 
companion object, I use the following logic. When family is not tweedie and 
link is set,  or when family is tweedie and linkPower is set, I will use 
`Link.fromParams` to construct the Link object. Otherwise, use the default link 
from the corresponding family.  
    
    So, if the user does not specify `linkPower`,  the link object will be the 
default `new Power(1 - variancePower)` set in the `Tweedie` class. The test for 
`tweedie family against glm (default power link)` covers this. The reason for 
not setting a default linkPower in the param map is to mimic the existing 
behavior: for tweedie with variancePower = 0, this will be the Gaussian with 
the identity link;  for tweedie with variancePower = 1, this will be the 
Poisson with the log link; etc.   
    
    ```
         val linkObj = if ((params.getFamily != "tweedie" && 
params.isDefined(params.link)) ||
            (params.getFamily == "tweedie" && 
params.isDefined(params.linkPower))) {
            Link.fromParams(params)
          } else {
            familyObj.defaultLink
          }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to