Class Encoder

java.lang.Object
com.jml.preprocessing.Encoder

public class Encoder extends Object
Contains methods to encode classes or targets to numerical values. This allows labels to be used as targets when fitting a Model.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int[]
    encodeClasses​(int[] labels)
    Encodes a list of classes as values between 0 to (n-1) classes.
    static int[]
    encodeClasses​(String[] labels)
    Encodes a list of classes as values between 0 to (n-1) classes.

    Labels will be sorted lexicographically before encoding.
    static int[]
    encodeClasses​(String[][] labels)
    Encodes a list of classes as values between 0 t0 (n-1) classes.
    WARNING: This method only flattens the array and calls encodeClasses(String[]).

    Labels will be sorted alphabetically before encoding.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • encodeClasses

      public static int[] encodeClasses(int[] labels)
      Encodes a list of classes as values between 0 to (n-1) classes.

      Labels will be sorted lexicographically before encoding. This guarantees a consistent method of encoding so that the encoded labels can be decoded.
      Parameters:
      labels - Labels of a dataset.
      Returns:
      An integer array containing the encoding of each label.
    • encodeClasses

      public static int[] encodeClasses(String[] labels)
      Encodes a list of classes as values between 0 to (n-1) classes.

      Labels will be sorted lexicographically before encoding. This guarantees a consistent method of encoding so that the encoded labels can be decoded.
      Parameters:
      labels - Labels of a dataset.
      Returns:
      An integer array containing the encoding of each label.
    • encodeClasses

      public static int[] encodeClasses(String[][] labels)
      Encodes a list of classes as values between 0 t0 (n-1) classes.
      WARNING: This method only flattens the array and calls encodeClasses(String[]).

      Labels will be sorted alphabetically before encoding. This guarantees a consistent method of encoding so that the encoded labels can be decoded.
      Parameters:
      labels - Labels of a dataset.
      Returns:
      An integer array containing the encoding of each label.