zhengruifeng commented on a change in pull request #31160:
URL: https://github.com/apache/spark/pull/31160#discussion_r556234110
##########
File path: mllib/src/main/scala/org/apache/spark/ml/feature/ChiSqSelector.scala
##########
@@ -44,6 +44,7 @@ import org.apache.spark.sql.types.StructType
* By default, the selection method is `numTopFeatures`, with the default
number of top features
* set to 50.
*/
+@deprecated("use UnivariateFeatureSelector instead", "3.1.0")
Review comment:
Should we change "3.1.0" to "3.1.1"?
##########
File path:
mllib/src/main/scala/org/apache/spark/ml/feature/UnivariateFeatureSelector.scala
##########
@@ -0,0 +1,554 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.ml.feature
+
+import scala.collection.mutable.ArrayBuilder
+
+import org.apache.hadoop.fs.Path
+
+import org.apache.spark.annotation.Since
+import org.apache.spark.ml.{Estimator, Model}
+import org.apache.spark.ml.attribute.{Attribute, AttributeGroup,
NominalAttribute, NumericAttribute}
+import org.apache.spark.ml.linalg.{DenseVector, SparseVector, Vector, Vectors,
VectorUDT}
+import org.apache.spark.ml.param._
+import org.apache.spark.ml.param.shared.{HasFeaturesCol, HasLabelCol,
HasOutputCol}
+import org.apache.spark.ml.stat.{ANOVATest, ChiSquareTest, FValueTest}
+import org.apache.spark.ml.util._
+import org.apache.spark.sql.{DataFrame, Dataset}
+import org.apache.spark.sql.functions.{col, udf}
+import org.apache.spark.sql.types.{StructField, StructType}
+
+
+/**
+ * Params for [[UnivariateFeatureSelector]] and
[[UnivariateFeatureSelectorModel]].
+ */
+private[feature] trait UnivariateFeatureSelectorParams extends Params
+ with HasFeaturesCol with HasLabelCol with HasOutputCol {
+
+ /**
+ * The feature type.
+ * Supported options: "categorical", "continuous"
+ * @group param
+ */
+ @Since("3.1.0")
+ final val featureType = new Param[String](this, "featureType",
+ "Feature type. Supported options: categorical, continuous.",
+ ParamValidators.inArray(Array("categorical", "continuous")))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getFeatureType: String = $(featureType)
+
+ /**
+ * The label type.
+ * Supported options: "categorical", "continuous"
+ * @group param
+ */
+ @Since("3.1.0")
+ final val labelType = new Param[String](this, "labelType",
+ "Label type. Supported options: categorical, continuous.",
+ ParamValidators.inArray(Array("categorical", "continuous")))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getLabelType: String = $(labelType)
+
+ /**
+ * Score funcion.
+ * Supported options: "chi2" (for categorical features and categorical
labels)
+ * "f_classif" (for continuous features and categorical
labels)
+ * "f_regression" (for continuous features and continuous
labels)
+ * @group param
+ */
+ @Since("3.1.0")
+ final val scoreFunction = new Param[String](this, "scoreFunction",
+ "Score Function. Supported options: chi2, f_classif, f_regression.",
+ ParamValidators.inArray(Array("chi2", "f_classif", "f_regression")))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getScoreFunction: String = $(scoreFunction)
+
+ /**
+ * The selector type.
+ * Supported options: "numTopFeatures" (default), "percentile", "fpr",
"fdr", "fwe"
+ * @group param
+ */
+ @Since("3.1.0")
+ final val selectorType = new Param[String](this, "selectorType",
+ "The selector type. Supported options: numTopFeatures, percentile, fpr,
fdr, fwe",
+ ParamValidators.inArray(Array("numTopFeatures", "percentile", "fpr", "fdr",
+ "fwe")))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getSelectorType: String = $(selectorType)
+
+ /**
+ * Number of features that selector will select, ordered by ascending
p-value. If the
+ * number of features is less than numTopFeatures, then this will select all
features.
+ * Only applicable when selectorType = "numTopFeatures".
+ * The default value of numTopFeatures is 50.
+ *
+ * @group param
+ */
+ @Since("3.1.0")
+ final val numTopFeatures = new IntParam(this, "numTopFeatures",
+ "Number of features that selector will select, ordered by ascending
p-value. If the" +
+ " number of features is < numTopFeatures, then this will select all
features.",
+ ParamValidators.gtEq(1))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getNumTopFeatures: Int = $(numTopFeatures)
+
+ /**
+ * Percentile of features that selector will select, ordered by ascending
p-value.
+ * Only applicable when selectorType = "percentile".
+ * Default value is 0.1.
+ * @group param
+ */
+ @Since("3.1.0")
+ final val percentile = new DoubleParam(this, "percentile",
+ "Percentile of features that selector will select, ordered by ascending
p-value.",
+ ParamValidators.inRange(0, 1))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getPercentile: Double = $(percentile)
+
+ /**
+ * The highest p-value for features to be kept.
+ * Only applicable when selectorType = "fpr".
+ * Default value is 0.05.
+ * @group param
+ */
+ @Since("3.1.0")
+ final val fpr = new DoubleParam(this, "fpr", "The highest p-value for
features to be kept.",
+ ParamValidators.inRange(0, 1))
+
+ /** @group getParam */
+ @Since("3.1.0")
+ def getFpr: Double = $(fpr)
+
+ /**
+ * The upper bound of the expected false discovery rate.
+ * Only applicable when selectorType = "fdr".
+ * Default value is 0.05.
+ * @group param
+ */
+ @Since("3.1.0")
+ final val fdr = new DoubleParam(this, "fdr",
+ "The upper bound of the expected false discovery rate.",
ParamValidators.inRange(0, 1))
+
+ /** @group getParam */
+ def getFdr: Double = $(fdr)
+
+ /**
+ * The upper bound of the expected family-wise error rate.
+ * Only applicable when selectorType = "fwe".
+ * Default value is 0.05.
+ * @group param
+ */
+ @Since("3.1.0")
+ final val fwe = new DoubleParam(this, "fwe",
+ "The upper bound of the expected family-wise error rate.",
ParamValidators.inRange(0, 1))
+
+ /** @group getParam */
+ def getFwe: Double = $(fwe)
+
+ setDefault(numTopFeatures -> 50, percentile -> 0.1, fpr -> 0.05, fdr ->
0.05, fwe -> 0.05,
+ selectorType -> "numTopFeatures")
+}
+
+/**
+ * UnivariateFeatureSelector
+ * User can either
Review comment:
We have only three test functions, and there are three params to choose
one, I personally think it is a over-kill.
----------------------------------------------------------------
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]