Class SparseEncoder

java.lang.Object
smile.feature.extraction.SparseEncoder
All Implemented Interfaces:
Function<Tuple,SparseArray>

public class SparseEncoder extends Object implements Function<Tuple,SparseArray>
Encodes numeric and categorical features into sparse array with on-hot encoding of categorical variables.
  • Constructor Details

    • SparseEncoder

      public SparseEncoder(StructType schema, String... columns)
      Constructor.
      Parameters:
      schema - the data frame schema.
      columns - the column names of variables to encode. If empty, all numeric and categorical columns will be used.
  • Method Details

    • apply

      public SparseArray apply(Tuple x)
      Generates the sparse representation of given object.
      Specified by:
      apply in interface Function<Tuple,SparseArray>
      Parameters:
      x - an object of interest.
      Returns:
      the sparse feature vector.
    • apply

      public SparseArray[] apply(DataFrame data)
      Generates the sparse representation of a data frame.
      Parameters:
      data - a data frame.
      Returns:
      the sparse feature vectors.