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

    https://github.com/apache/spark/pull/10355#discussion_r48050215
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/OneVsRestSuite.scala ---
    @@ -160,6 +160,59 @@ class OneVsRestSuite extends SparkFunSuite with 
MLlibTestSparkContext {
           require(m.getThreshold === 0.1, "copy should handle extra model 
params")
         }
       }
    +
    +  test("should support all NumericType labels") {
    +    val df = sqlContext.createDataFrame(Seq(
    +      (0, Vectors.dense(0, 2, 3)),
    +      (1, Vectors.dense(0, 3, 1)),
    +      (0, Vectors.dense(0, 2, 2)),
    +      (1, Vectors.dense(0, 3, 9)),
    +      (2, Vectors.dense(0, 2, 6))
    +    )).toDF("label", "features")
    +
    +    val types =
    +      Seq(ShortType, LongType, IntegerType, FloatType, ByteType, 
DoubleType, DecimalType(10, 0))
    +
    +    var dfWithTypes = df
    +    types.foreach(t => dfWithTypes = dfWithTypes.withColumn(t.toString, 
df("label").cast(t)))
    +
    +    val ovr = new OneVsRest()
    +      .setClassifier(new LogisticRegression)
    +      .setFeaturesCol("features")
    +
    +    val expected = ovr.setLabelCol(DoubleType.toString).fit(dfWithTypes)
    +    val expectedModels = expected.models.map(m => 
m.asInstanceOf[LogisticRegressionModel])
    +    types.filter(_ != DoubleType).foreach { t =>
    +      val actual = ovr.setLabelCol(t.toString).fit(dfWithTypes)
    +      val actualModels = actual.models.map(m => 
m.asInstanceOf[LogisticRegressionModel])
    +      assert(expectedModels.length === actualModels.length)
    +      expectedModels.zip(actualModels).foreach { case (e, a) =>
    +        assert(e.intercept === a.intercept)
    +        assert(e.coefficients.toArray === a.coefficients.toArray)
    +      }
    +    }
    +  }
    +
    +  test("shouldn't support non NumericType labels") {
    +    val dfWithStringLabels = sqlContext.createDataFrame(Seq(
    +      ("0", Vectors.dense(0, 2, 3)),
    +      ("1", Vectors.dense(0, 3, 1)),
    +      ("0", Vectors.dense(0, 2, 2)),
    +      ("1", Vectors.dense(0, 3, 9)),
    +      ("2", Vectors.dense(0, 2, 6))
    +    )).toDF("label", "features")
    +
    +    val ovr = new OneVsRest()
    +      .setClassifier(new LogisticRegression)
    +      .setLabelCol("label")
    +      .setFeaturesCol("features")
    +
    +    // thrown by AttributeFactory#fromStructField and not by 
Predictor#validateAndTransformSchema
    +    // because OneVsRest reimplements the fit method
    +    intercept[IllegalArgumentException] {
    --- End diff --
    
    This is caused by 
[AttributeFactory#fromStructField](https://github.com/apache/spark/blob/master/mllib/src/main/scala/org/apache/spark/ml/attribute/attributes.scala#L130).
    
    I don't know what's the best way to handle this, input welcome.


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