Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/8102#discussion_r37350805
--- Diff: python/pyspark/ml/feature.py ---
@@ -950,6 +950,92 @@ class VectorIndexerModel(JavaModel):
@inherit_doc
+class VectorSlicer(JavaTransformer, HasInputCol, HasOutputCol):
+ """
+ .. note:: Experimental
+
+ This class takes a feature vector and outputs a new feature vector
with a subarray
+ of the original features.
+
+ The subset of features can be specified with either indices
(`setIndices()`)
+ or names (`setNames()`). At least one feature must be selected.
Duplicate features
+ are not allowed, so there can be no overlap between selected indices
and names.
+
+ The output vector will order features with the selected indices first
(in the order given),
+ followed by the selected names (in the order given).
+
+ >>> from pyspark.mllib.linalg import Vectors
+ >>> df = sqlContext.createDataFrame([
+ ... (Vectors.dense([-2.0, 2.3, 0.0, 0.0, 1.0]),),
+ ... (Vectors.dense([0.0, 0.0, 0.0, 0.0, 0.0]),),
+ ... (Vectors.dense([0.6, -1.1, -3.0, 4.5, 3.3]),)], ["features"])
+ >>> vs = VectorSlicer(inputCol="features", outputCol="expected",
indices=[1, 4])
+ >>> vs.transform(df).head().expected
+ DenseVector([2.3, 1.0])
+ """
+
+ # a placeholder to make it appear in the generated doc
+ indices = Param(Params._dummy(), "indices", "An array of indices to
select features from " +
+ "a vector column. There can be no overlap with
`names`.")
+ names = Param(Params._dummy(), "names", "An array of feature names to
select features from " +
+ "a vector column. These names must be specified by ML " +
+ "`org.apache.spark.ml.attribute.Attribute`s. There can
be no overlap with " +
--- End diff --
No need for backtick within strings; the backtick is only for formatting
generated API docs. (here and elsewhere)
---
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]