Github user mpjlu commented on a diff in the pull request:
https://github.com/apache/spark/pull/14597#discussion_r77137991
--- Diff: python/pyspark/mllib/feature.py ---
@@ -276,24 +276,64 @@ class ChiSqSelector(object):
"""
Creates a ChiSquared feature selector.
- :param numTopFeatures: number of features that selector will select.
-
>>> data = [
... LabeledPoint(0.0, SparseVector(3, {0: 8.0, 1: 7.0})),
... LabeledPoint(1.0, SparseVector(3, {1: 9.0, 2: 6.0})),
... LabeledPoint(1.0, [0.0, 9.0, 8.0]),
... LabeledPoint(2.0, [8.0, 9.0, 5.0])
... ]
- >>> model = ChiSqSelector(1).fit(sc.parallelize(data))
+ >>> model =
ChiSqSelector().setNumTopFeatures(1).fit(sc.parallelize(data))
+ >>> model.transform(SparseVector(3, {1: 9.0, 2: 6.0}))
+ SparseVector(1, {0: 6.0})
+ >>> model.transform(DenseVector([8.0, 9.0, 5.0]))
+ DenseVector([5.0])
+ >>> model =
ChiSqSelector().setPercentile(0.34).fit(sc.parallelize(data))
>>> model.transform(SparseVector(3, {1: 9.0, 2: 6.0}))
SparseVector(1, {0: 6.0})
>>> model.transform(DenseVector([8.0, 9.0, 5.0]))
DenseVector([5.0])
+ >>> data = [
+ ... LabeledPoint(0.0, SparseVector(4, {0: 8.0, 1: 7.0})),
+ ... LabeledPoint(1.0, SparseVector(4, {1: 9.0, 2: 6.0, 3: 4.0})),
+ ... LabeledPoint(1.0, [0.0, 9.0, 8.0, 4.0]),
+ ... LabeledPoint(2.0, [8.0, 9.0, 5.0, 9.0])
+ ... ]
+ >>> model = ChiSqSelector().setAlpha(0.1).fit(sc.parallelize(data))
+ >>> model.transform(DenseVector([1.0,2.0,3.0,4.0]))
+ DenseVector([4.0])
.. versionadded:: 1.4.0
"""
- def __init__(self, numTopFeatures):
- self.numTopFeatures = int(numTopFeatures)
+ def __init__(self):
+ self.param = 50
--- End diff --
Hi @srowen , use different fields for different value is not a problem,
just need another selectionType field, and in the fit function, the code will
be:
if(selectionType == KBest)
callMLlibFunc("fitChiSqSelectorKBest", self.numTopFeatures, data)
elseif(selectionType == Percentile)
callMLlibFunc("fitChiSqSelectorKPercentile", self.percentile, data)
elseif(selecitonType == FPR)
callMLlibFunc("fitChiSqSelectorFPR", self.alpha, data)
Is that ok? Thanks.
---
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]