Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/10186#discussion_r47074185
--- Diff: python/pyspark/ml/feature.py ---
@@ -2093,6 +2093,95 @@ class RFormulaModel(JavaModel):
"""
+@inherit_doc
+class ChiSqSelector(JavaEstimator, HasFeaturesCol, HasOutputCol,
HasLabelCol):
+ """
+ .. note:: Experimental
+
+ # Chi-Squared feature selection, which selects categorical features to
use for predicting a
+ # categorical label.
+
+ >>> from pyspark.mllib.linalg import Vectors
+ >>> df = sqlContext.createDataFrame(
+ ... [(Vectors.dense([0.0, 0.0, 18.0, 1.0]), 1.0),
+ ... (Vectors.dense([0.0, 1.0, 12.0, 0.0]), 0.0),
+ ... (Vectors.dense([1.0, 0.0, 15.0, 0.1]), 0.0)],
+ ... ["features", "label"])
+ >>> selector = ChiSqSelector(numTopFeatures=1,
outputCol="selectedFeatures")
+ >>> model = selector.fit(df)
+ >>> model.transform(df).collect()[0].selectedFeatures
+ DenseVector([1.0])
+ >>> model.transform(df).collect()[1].selectedFeatures
+ DenseVector([0.0])
+ >>> model.transform(df).collect()[2].selectedFeatures
+ DenseVector([0.1])
+
+ .. versionadded:: 1.6.0
+ """
+
+ # a placeholder to make it appear in the generated doc
+ numTopFeatures = \
+ Param(Params._dummy(), "numTopFeatures",
+ "Number of features that selector will select, ordered by
statistics value " +
+ "descending. If the number of features is < numTopFeatures,
then this will select " +
+ "all features.")
+
+ @keyword_only
+ def __init__(self, numTopFeatures=50, featuresCol="features",
outputCol=None, labelCol="label"):
+ """
+ __init__(self, numTopFeatures=50, featuresCol="features",
outputCol=None, labelCol="label")
+ """
+ super(ChiSqSelector, self).__init__()
+ self._java_obj =
self._new_java_obj("org.apache.spark.ml.feature.ChiSqSelector", self.uid)
+ self.numTopFeatures = \
+ Param(self, "numTopFeatures",
+ "Number of features that selector will select, ordered
by statistics value " +
+ "descending. If the number of features is <
numTopFeatures, then this will " +
+ "select all features.")
+ kwargs = self.__init__._input_kwargs
+ self.setParams(**kwargs)
+
+ @keyword_only
+ @since("1.6.0")
+ def setParams(self, numTopFeatures=50, featuresCol="features",
outputCol=None,
+ labelCol="labels"):
+ """
+ setParams(self, numTopFeatures=50, featuresCol="features",
outputCol=None,
--- End diff --
add \
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]