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

    https://github.com/apache/spark/pull/12066#discussion_r61474435
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/ml/classification/Classifier.scala ---
    @@ -37,8 +37,38 @@ private[spark] trait ClassifierParams
           schema: StructType,
           fitting: Boolean,
           featuresDataType: DataType): StructType = {
    -    val parentSchema = super.validateAndTransformSchema(schema, fitting, 
featuresDataType)
    -    SchemaUtils.appendColumn(parentSchema, $(rawPredictionCol), new 
VectorUDT)
    +    // TODO: Support casting Array[Double] and Array[Float] to Vector when 
FeaturesType = Vector
    +    SchemaUtils.checkColumnType(schema, $(featuresCol), featuresDataType)
    +    if (fitting) {
    +      SchemaUtils.checkNumericType(schema, $(labelCol))
    +    }
    +    val newSchema = SchemaUtils.appendColumn(schema, $(predictionCol), 
DoubleType,
    +      nullable = false, generatePredictionMetadata(schema))
    +    SchemaUtils.appendColumn(newSchema, $(rawPredictionCol), new VectorUDT)
    +  }
    +
    +  protected def generatePredictionMetadata(schema: StructType): Metadata = 
{
    +    // The label column for base binary classifier of OneVsRest will not 
be retained during
    +    // model transformation, so we should not handle label column metadata 
as well.
    +    if (schema.fieldNames.contains($(labelCol))) {
    +      // determine number of classes either from metadata if provided.
    +      val labelSchema = schema($(labelCol))
    +      MetadataUtils.getNumClasses(labelSchema) match {
    +        case Some(numClasses) =>
    +          // extract label metadata from label column if present, or 
create a nominal attribute
    +          // to output the number of labels
    +          val labelAttribute = Attribute.fromStructField(labelSchema) 
match {
    +            case _: NumericAttribute | UnresolvedAttribute =>
    +              
NominalAttribute.defaultAttr.withName($(predictionCol)).withNumValues(numClasses)
    +            case attr: Attribute => attr
    +          }
    +          labelAttribute.toMetadata()
    +        case None =>
    +          Metadata.empty
    --- End diff --
    
    You could do ```NominalAttribute.defaultAttr.withName($(predictionCol))``` 
instead of Metadata.empty


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