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

    https://github.com/apache/spark/pull/7574#discussion_r35279252
  
    --- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala 
---
    @@ -62,19 +77,60 @@ class RFormula(override val uid: String)
       /** @group getParam */
       def getFormula: String = $(formula)
     
    -  /** @group getParam */
    -  def setFeaturesCol(value: String): this.type = set(featuresCol, value)
    +  override def fit(dataset: DataFrame): RFormulaModel = {
    +    require(parsedFormula.isDefined, "Must call setFormula() first.")
    +    val factorLevels = parsedFormula.get.terms.flatMap { term =>
    +      dataset.schema(term) match {
    +        case column if column.dataType == StringType =>
    +          val idxTerm = term + "_idx_" + uid
    +          val indexer = new 
StringIndexer().setInputCol(term).setOutputCol(idxTerm)
    +          Some(term -> indexer.fit(dataset))
    +        case _ =>
    +          None
    --- End diff --
    
    It might be simpler to construct the entire preprocessing pipeline in 
`fit`, which includes `StringIndexer`s, `OneHotEncoder`, and `VectorAssembler`. 
Then call `fit` on the pipeline and pass the `PipelineModel` to 
`RFormulaModel`. We might add `StringVectorizer` to combine `StringIndexer` and 
`OneHotEncoder` in the future.
    
    I'm a little worried about the generated feature names. But we could 
address this issue separately.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to