spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From avulanov <>
Subject [GitHub] spark pull request #14597: [SPARK-17017][MLLIB] add a chiSquare Selector bas...
Date Fri, 12 Aug 2016 10:19:33 GMT
Github user avulanov commented on a diff in the pull request:
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/feature/ChiSqSelector.scala ---
    @@ -197,3 +197,28 @@ class ChiSqSelector @Since("1.3.0") (
         new ChiSqSelectorModel(indices)
    + * Creates a ChiSquared feature selector by False Positive Rate (FPR) test.
    + * @param alpha the highest p-value for features to be kept
    + */
    +class ChiSqSelectorByFpr @Since("2.1.0") (
    +  @Since("2.1.0") val alpha: Double) extends Serializable {
    +  /**
    +   * Returns a ChiSquared feature selector by FPR.
    +   *
    +   * @param data an `RDD[LabeledPoint]` containing the labeled dataset with categorical
    +   *             Real-valued features will be treated as categorical for each distinct
    +   *             Apply feature discretizer before using this function.
    +   */
    +  @Since("2.1.0")
    +  def fit(data: RDD[LabeledPoint]): ChiSqSelectorModel = {
    +    val indices = Statistics.chiSqTest(data)
    +      .zipWithIndex.filter { case (res, _) => res.pValue < alpha }
    --- End diff --
    @srowen I've checked our thread with @mengxr on that feature

      - We preserve the order of indexes to make the selection of features with one loop (i.e.
linear time complexity). Here is the code:
The logic of feature selector, which is selection of N top features, does not imply that it
will sort the features by their Chi-square value. A parameter must be introduced if it is
required for some use-case.
      - We were planning to include Chi-square values in the model later if needed
    @mpjlu It seems that FPR feature selection should not modify the code of existing `ChiSqSelector`,
because FPR feature selection works on top of a scoring function rather than on top of another
selector. Scoring function is a parameter, and it might be Chi-square. For example, please
refer to Sklearn's `FPR` implementation mentioned. It uses ANOVA as a default scoring function

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 or file a JIRA ticket
with INFRA.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message