Class SparseEncoder

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

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

    Constructors
    Constructor
    Description
    SparseEncoder(smile.data.type.StructType schema, String... columns)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    smile.util.SparseArray[]
    apply(smile.data.DataFrame data)
    Generates the sparse representation of a data frame.
    smile.util.SparseArray
    apply(smile.data.Tuple x)
    Generates the sparse representation of given object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Function

    andThen, compose
  • Constructor Details

    • SparseEncoder

      public SparseEncoder(smile.data.type.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 smile.util.SparseArray apply(smile.data.Tuple x)
      Generates the sparse representation of given object.
      Specified by:
      apply in interface Function<smile.data.Tuple,smile.util.SparseArray>
      Parameters:
      x - an object of interest.
      Returns:
      the sparse feature vector.
    • apply

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