Class VectorIndexerModel

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

public class VectorIndexerModel extends Model<VectorIndexerModel> implements VectorIndexerParams, MLWritable
Model fitted by VectorIndexer. Transform categorical features to use 0-based indices instead of their original values. - Categorical features are mapped to indices. - Continuous features (columns) are left unchanged. This also appends metadata to the output column, marking features as Numeric (continuous), Nominal (categorical), or Binary (either continuous or categorical). Non-ML metadata is not carried over from the input to the output column.

This maintains vector sparsity.

param: numFeatures Number of features, i.e., length of Vectors which this transforms param: categoryMaps Feature value index. Keys are categorical feature indices (column indices). Values are maps from original features values to 0-based category indices. If a feature is not in this map, it is treated as continuous.

See Also:
  • Method Details

    • read

      public static MLReader<VectorIndexerModel> read()
    • load

      public static VectorIndexerModel load(String path)
    • handleInvalid

      public Param<String> handleInvalid()
      Description copied from interface: VectorIndexerParams
      Param for how to handle invalid data (unseen labels or NULL values). Note: this param only applies to categorical features, not continuous ones. Options are: 'skip': filter out rows with invalid data. 'error': throw an error. 'keep': put invalid data in a special additional bucket, at index of the number of categories of the feature. Default value: "error"
      Specified by:
      handleInvalid in interface HasHandleInvalid
      Specified by:
      handleInvalid in interface VectorIndexerParams
      Returns:
      (undocumented)
    • maxCategories

      public IntParam maxCategories()
      Description copied from interface: VectorIndexerParams
      Threshold for the number of values a categorical feature can take. If a feature is found to have > maxCategories values, then it is declared continuous. Must be greater than or equal to 2.

      (default = 20)

      Specified by:
      maxCategories in interface VectorIndexerParams
      Returns:
      (undocumented)
    • outputCol

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

      public final Param<String> inputCol()
      Description copied from interface: HasInputCol
      Param for input column name.
      Specified by:
      inputCol in interface HasInputCol
      Returns:
      (undocumented)
    • 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
      Returns:
      (undocumented)
    • numFeatures

      public int numFeatures()
    • categoryMaps

      public scala.collection.immutable.Map<Object,scala.collection.immutable.Map<Object,Object>> categoryMaps()
    • javaCategoryMaps

      public Map<Integer,Map<Double,Integer>> javaCategoryMaps()
      Java-friendly version of categoryMaps()
    • setInputCol

      public VectorIndexerModel setInputCol(String value)
    • setOutputCol

      public VectorIndexerModel 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
      Parameters:
      dataset - (undocumented)
      Returns:
      (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
      Parameters:
      schema - (undocumented)
      Returns:
      (undocumented)
    • copy

      public VectorIndexerModel 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 Model<VectorIndexerModel>
      Parameters:
      extra - (undocumented)
      Returns:
      (undocumented)
    • write

      public MLWriter write()
      Description copied from interface: MLWritable
      Returns an MLWriter instance for this ML instance.
      Specified by:
      write in interface MLWritable
      Returns:
      (undocumented)
    • toString

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