Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/12467#discussion_r60735190
--- Diff: mllib/src/main/scala/org/apache/spark/ml/feature/RFormula.scala
---
@@ -254,8 +254,8 @@ class RFormulaModel private[feature](
val columnNames = schema.map(_.name)
require(!columnNames.contains($(featuresCol)), "Features column
already exists.")
require(
- !columnNames.contains($(labelCol)) || schema($(labelCol)).dataType
== DoubleType,
- "Label column already exists and is not of type DoubleType.")
+ !columnNames.contains($(labelCol)) ||
schema($(labelCol)).dataType.isInstanceOf[NumericType],
--- End diff --
@MLnick The code in master is right.
For the first example:
```
scala> val original = sqlContext.createDataFrame(Seq((0, 1), (2,
2))).toDF("x", "y")
original: org.apache.spark.sql.DataFrame = [x: int, y: int]
scala> formula.fit(original).transform(original).show
+---+---+--------+-----+
| x| y|features|label|
+---+---+--------+-----+
| 0| 1| [0.0]| 1.0|
| 2| 2| [2.0]| 2.0|
+---+---+--------+-----+
```
It confirms with the design of ```RFormula``` which transform dataset with
column names ```a, b``` to two columns: ```label``` and ```features```.
For the second one:
It make sense that L244 catch this exception. In this example, we can not
transform ```y``` whose type is ```Seq``` to ```label```, so throw exception
inside of function ```transformLabel``` is reasonable.
In ```checkCanTransform``` we only have two kinds of guarantee:
#1 Label column not exists.
#2 If label column exists, it must be type of ```Double/Numeric```. If we
are in this situation, we will fall into branch ```if
(hasLabelCol(dataset.schema))``` of ```transformLabel```.
---
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]