Github user MLnick commented on the issue:

    https://github.com/apache/spark/pull/13481
  
    Yeah actually looking at it the Scala side is a bit ugly. We can make it 
prettier there and then just call into it from PySpark, e.g.
    
    ```
    scala> val formula = new RFormula().setFormula("clicked ~ country + hour + 
country:hour").setFeaturesCol("features") .setLabelCol("label")
    formula: org.apache.spark.ml.feature.RFormula = RFormula(clicked ~ country 
+ hour + country:hour) (uid=rFormula_7e1422944cda)
    
    scala> val model = formula.fit(dataset)
    model: org.apache.spark.ml.feature.RFormulaModel = 
RFormulaModel(ResolvedRFormula(label=clicked, 
terms=[country,hour,{country,hour}], hasIntercept=true)) 
(uid=rFormula_7e1422944cda)
    ```
    and 
    ```
    In [8]: rf._call_java("toString")
    Out[8]: u'RFormula(y ~ x + s) (uid=RFormula_495190a2bd89e76b710f)'
    
    In [9]: model._call_java("toString")
    Out[9]: u'RFormulaModel(ResolvedRFormula(label=y, terms=[x,s], 
hasIntercept=true)) (uid=RFormula_495190a2bd89e76b710f)'
    ```
    
    This is achieved by amending `RFormula.toString` (by the way on second 
thought I prefer your approach of empty string instead of None):
    ```scala
    override def toString: String = s"RFormula(${get(formula).getOrElse("")}) 
(uid=$uid)"
    ```
    
    And overriding `ResolvedRFormula.toString`:
    
    ```scala
    private[ml] case class ResolvedRFormula(
      label: String, terms: Seq[Seq[String]], hasIntercept: Boolean) {
    
      override def toString: String = {
        val ts = terms.map {
          case t if t.length > 1 =>
            s"${t.mkString("{", ",", "}")}"
          case t =>
            t.mkString
        }
        val termStr = ts.mkString("[", ",", "]")
        s"ResolvedRFormula(label=$label, terms=$termStr, 
hasIntercept=$hasIntercept)"
      }
    }
    ```
    
    cc @yanboliang 


---
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