You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2020/04/12 00:15:25 UTC
[GitHub] [spark] huaxingao commented on a change in pull request #28176:
[SPARK-31301][ML] Flatten the result dataframe of tests in testChiSquare
huaxingao commented on a change in pull request #28176: [SPARK-31301][ML] Flatten the result dataframe of tests in testChiSquare
URL: https://github.com/apache/spark/pull/28176#discussion_r407126004
##########
File path: mllib/src/main/scala/org/apache/spark/ml/stat/ChiSquareTest.scala
##########
@@ -63,40 +55,47 @@ object ChiSquareTest {
*/
@Since("2.2.0")
def test(dataset: DataFrame, featuresCol: String, labelCol: String): DataFrame = {
- val spark = dataset.sparkSession
- import spark.implicits._
-
- SchemaUtils.checkColumnType(dataset.schema, featuresCol, new VectorUDT)
- SchemaUtils.checkNumericType(dataset.schema, labelCol)
- val rdd = dataset.select(col(labelCol).cast("double"), col(featuresCol)).as[(Double, Vector)]
- .rdd.map { case (label, features) => OldLabeledPoint(label, OldVectors.fromML(features)) }
- val testResults = OldStatistics.chiSqTest(rdd)
- val pValues = Vectors.dense(testResults.map(_.pValue))
- val degreesOfFreedom = testResults.map(_.degreesOfFreedom)
- val statistics = Vectors.dense(testResults.map(_.statistic))
- spark.createDataFrame(Seq(ChiSquareResult(pValues, degreesOfFreedom, statistics)))
+ test(dataset, featuresCol, labelCol, false)
}
/**
* @param dataset DataFrame of categorical labels and categorical features.
* Real-valued features will be treated as categorical for each distinct value.
* @param featuresCol Name of features column in dataset, of type `Vector` (`VectorUDT`)
* @param labelCol Name of label column in dataset, of any numerical type
- * @return Array containing the SelectionTestResult for every feature against the label.
+ * @param flatten If false, the returned DataFrame contains only a single Row, otherwise, one
Review comment:
I am OK with the change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org