Class VectorSlicer

All Implemented Interfaces:
Serializable, org.apache.spark.internal.Logging, Params, HasInputCol, HasOutputCol, DefaultParamsWritable, Identifiable, MLWritable, scala.Serializable

public final class VectorSlicer extends Transformer implements HasInputCol, HasOutputCol, DefaultParamsWritable
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).

See Also:
  • Constructor Details

    • VectorSlicer

      public VectorSlicer(String uid)
    • VectorSlicer

      public VectorSlicer()
  • Method Details

    • load

      public static VectorSlicer load(String path)
    • read

      public static MLReader<T> read()
    • outputCol

      public final Param<String> outputCol()
      Description copied from interface: HasOutputCol
      Param for output column name.
      Specified by:
      outputCol in interface HasOutputCol
    • inputCol

      public final Param<String> inputCol()
      Description copied from interface: HasInputCol
      Param for input column name.
      Specified by:
      inputCol in interface HasInputCol
    • uid

      public String uid()
      Description copied from interface: Identifiable
      An immutable unique ID for the object and its derivatives.
      Specified by:
      uid in interface Identifiable
    • indices

      public IntArrayParam indices()
      An array of indices to select features from a vector column. There can be no overlap with names(). Default: Empty array
    • getIndices

      public int[] getIndices()
    • setIndices

      public VectorSlicer setIndices(int[] value)
    • names

      public StringArrayParam names()
      An array of feature names to select features from a vector column. These names must be specified by ML Attributes. There can be no overlap with indices(). Default: Empty Array
    • getNames

      public String[] getNames()
    • setNames

      public VectorSlicer setNames(String[] value)
    • setInputCol

      public VectorSlicer setInputCol(String value)
    • setOutputCol

      public VectorSlicer setOutputCol(String value)
    • transform

      public Dataset<Row> transform(Dataset<?> dataset)
      Description copied from class: Transformer
      Transforms the input dataset.
      Specified by:
      transform in class Transformer
      dataset - (undocumented)
    • transformSchema

      public StructType transformSchema(StructType schema)
      Description copied from class: PipelineStage
      Check transform validity and derive the output schema from the input schema.

      We check validity for interactions between parameters during transformSchema and raise an exception if any parameter value is invalid. Parameter value checks which do not depend on other parameters are handled by Param.validate().

      Typical implementation should first conduct verification on schema change and parameter validity, including complex parameter interaction checks.

      Specified by:
      transformSchema in class PipelineStage
      schema - (undocumented)
    • copy

      public VectorSlicer copy(ParamMap extra)
      Description copied from interface: Params
      Creates a copy of this instance with the same UID and some extra params. Subclasses should implement this method and set the return type properly. See defaultCopy().
      Specified by:
      copy in interface Params
      Specified by:
      copy in class Transformer
      extra - (undocumented)
    • toString

      public String toString()
      Specified by:
      toString in interface Identifiable
      toString in class Object