Github user sethah commented on a diff in the pull request: https://github.com/apache/spark/pull/15314#discussion_r82082589 --- Diff: mllib/src/test/scala/org/apache/spark/ml/util/MLTestingUtils.scala --- @@ -104,19 +136,21 @@ object MLTestingUtils extends SparkFunSuite { def genClassifDFWithNumericLabelCol( spark: SparkSession, labelColName: String = "label", - featuresColName: String = "features"): Map[NumericType, DataFrame] = { + featuresColName: String = "features", + weightColName: String = "weight"): Map[NumericType, DataFrame] = { val df = spark.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)), - (0, Vectors.dense(0, 2, 6)) - )).toDF(labelColName, featuresColName) + (0, 1, Vectors.dense(0, 2, 3)), + (1, 2, Vectors.dense(0, 3, 1)), + (0, 2, Vectors.dense(0, 2, 2)), + (1, 1, Vectors.dense(0, 3, 9)), + (0, 1, Vectors.dense(0, 2, 6)) + )).toDF(labelColName, weightColName, featuresColName) val types = Seq(ShortType, LongType, IntegerType, FloatType, ByteType, DoubleType, DecimalType(10, 0)) types.map { t => - val castDF = df.select(col(labelColName).cast(t), col(featuresColName)) + val castDF = df.select(col(labelColName).cast(t), col(weightColName).cast(t), --- End diff -- `TreeTests.setMetadata` selects only the label and features column, so you set a weight column but return a df that does not contain it. The following worked for me: ````scala types.map { t => val castDF = df.select(col(labelColName).cast(t), col(featuresColName)) t -> TreeTests.setMetadata(castDF, 0, labelColName, featuresColName) .withColumn(censorColName, lit(0.0)) .withColumn(weightColName, ceil(rand() * 10).cast(t)) }.toMap ```` The weight column is just a column of random whole numbers between 0 and 10. This way, when we convert to types like `Short, Int, Long` we don't lose any information and the weights are still the same.
--- 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